How to add a hint text to a TextBox in a UserForm that will disappear once a user type anything in?
Add a Label element.
Type a hint text.
Set BackColor, Height, Left, Top, and Width properties to match that of the TextBox that will be added later.
Note: Setting BackColor to Window Background (from the drop-down list) will match the common background color of a text box.
Set ForeColor property (a different from TextBox text color allows to distinguish the hint text from the entered one).
Add a TextBox element.
Set BackColor, Height, Left, Top, and Width properties.
Set BackStyle property to fmBackStyleTransparent.
Add the following code to Sub TextBox_Change:
If TextBox.Value = "" Then
TextBox.BackStyle = fmBackStyleTransparent
Else
TextBox.BackStyle = fmBackStyleOpaque
End If
Here is the result:
Related
I have added a RichTextBoxColumn to DataGridView, want to change font style
Bold/Regular Font, ForeColor of a PART OF TEXT. But this does not work like Windows
RichTextBox Control. Please help.
My Code:
With DataGridView1
.Columns(4).DisplayIndex = 4
.Columns(4).ValueType = GetType(DataGridViewRichTextBoxCell)
.Columns(4).Width = 17
.Columns(4).DataGridView.DefaultCellStyle.Font = New Font(FontFamily
Name,
11.0!,System.Drawing.FontStyle.Bold)
End With
But, all Cells in Row get Bold.
I have added an Label on my Chart tab, but when I try to change it's font all of the fields are greyed out. I have searched enough but didn't find any solution. I am attaching a screenshot of my chart tab.
I want to change the font properties of this Label 10 on the chart tab. Is there a way I can access the properties by VBA.
To change the text I recorded a macro.
ActiveChart.Shapes("Label 10").Select
Selection.Characters.Text = "Mohit"
ActiveChart.ChartArea.Select
I tried the line code:
Selection.TextFrame.Characters.Font.Size = 20
but it doesn't work. is there a way to change the color and font size of this label ?
Alternate that I am using now
Now I am using Rectangle shape instead of Label. What I wanted to acheive was to display the name of the selected button ( PV , Terrorism or SRCC ) as an indication that this button have been selected. So I clicked PV and my series changed and Rectangle displayed the name of selected Peril.
Now if I select SRCC again the same thing happens.
For the code I only have to change the text of the rectangle every-time a button is pressed as I preset the font and size of text once which remains the same. I wasn't able to change the font and size of text with a label.
ActiveChart.Shapes("Label 10").Select
With Selection
.Characters.Text = "Mohit"
.Font.Size = 20
End With
or you can avoid Select/Selection accessing your Chart object by its name:
With Charts("ChartName").Shapes("Label 10").TextFrame2.TextRange
.Text = "Mohit"
.Font.Size = 20
End With
I basically programmatically generate many labels with a text read from a text file so I would like to know how I can programmatically adapt the width of a Label to its text.
Controls come in two flavors. The ActiveX version of a label has an AutoSize property. For example, with a ActiveX label control named Label1 in Sheet1
Private Sub test()
Sheet1.Label1.WordWrap = False
Sheet1.Label1.AutoSize = True
Sheet1.Label1.Caption = "This is a lot of text to put in a label"
End Sub
will automatically adjust the width to fit.
How to allow editing the value in the combolist of C1FlexGrid in vb10?
Is it not okay to type the value in the combolist of c1 flex grid?
I am using the following snippet
GridComboTransferStr = dbRow("RSPrice1") & "|" & Trim(GridComboTransferStr) & ""
ComboList in C1FlexGrid in a ComponentOne Studio for Winforms works analogous to ComboList in DatGridView of MS Controls. ComboList can be editable in C1FlexGrig in VB10. In fact it is an important and widely used functionality of C1FlexGrid.
The ComboList property of C1FlexGrid enables this functionality. It specifies the type of editor to be used when editing a cell. You may use a text box, drop-down list, drop-down combo, or an edit button to pop up custom editor forms.
To use the ComboList property, set the AllowEditing property to true and respond to the BeforeEdit event by setting the ComboList property to a string that describes the type of editing you want to use for that cell. The options are described below:
To edit the cell using a regular text box, set the ComboList property to an empty string. For example:
flex.ComboList = string.Empty
To edit the cell using a drop-down list, set the ComboList property to a string containing the available options, separated by pipe characters. For example:
flex.ComboList = "Item 1|Item 2|Item 3"
To edit the cell using a drop-down combo, set the ComboList property to a string containing the available options, separated by pipe characters ("|") and starting with a pipe character. For example:
flex.ComboList = "|Item 1|Item 2|Item 3"
To display an edit button, set the ComboList property to a string containing an ellipsis ("..."). Edit buttons look like regular push buttons, aligned to the right of the cell, with an ellipsis as a caption. When the user clicks on the edit button, the grid fires the CellButtonClick event. In this case, the user can't edit the cell contents directly. For example:
flex.ComboList = "..."
To display an edit button next to an editable cell, set the ComboList property to a string containing a pipe and an ellipsis ("|..."). In this case, you get a regular edit button but the user can also edit the cell contents directly. For example:
flex.ComboList = "|..."
Example:
The code below handles the BeforeEdit event and assigns a value to the ComboList property so that the grid displays buttons on every other row.
Private Sub _flex_BeforeEdit(sender As Object, e As RowColEventArgs)
_flex.ComboList = String.Empty
If e.Row Mod 2 = 0 Then
_flex.ComboList = "..."
End If
End Sub
I'm using VS2012 with VB.NET on a winforms application. I set the BackColor property of some textboxes programmatically during my code depending on form validation. This works fine, the problem is that I'd like to "reset" the BackColor property of the textbox, so that the textbox performs as if it were in the same state before I set the BackColor. So it would do the following:
Return to the default color of white immediately after "reset"
Change to that "light gray" color when the textbox.enabled = false
The reason why I cannot simply set the BackColor to Color.White, is that this affects the textbox when textbox.enabled = false. The textbox does not return that "light gray" color after setting the backcolor and disabling the textbox. I need it to return to that color, and I'd rather not have to set the textbox's color everytime I enable or disable the textbox. Thanks!
Simply:
TextBox1.BackColor = SystemColors.Window
You reset the color by re-assigning the original value of BackColor. Or by assigning the default value, it isn't white:
textBox1.BackColor = Color.FromKnownColor(KnownColor.Window);
textBox1.BackColor = SystemColors.Control;
This is an old post, but when I used SystemColors.Window it set it to white, not the default grey.