I have a maskedtextbox with the following mask : 999999. I would like to add something like a placeholder in HTML to help the end user to know the mask of my maskedtextbox.
I think that i can create a specific mask when the form load and set the text property to "YYYYMM" (the placeholder that i need) and when the user enter in the control, reset the text and change the mask to 999999. However, i think there are better solutions.
I find some people talking about watermark control, but i would like to find something easier to use.
Any help will be appreciate. Thanks
Use a DateTimePicker, that would be the easiest way, as suggested.
However, to do as the question asked...
On Form_Load, set MaskedTextBox1.Text = "YYYYMM"
Then, to get the effect of changing the mask to 999999 when the control is in focus, use the MaskedTextBox1_GotFocus method and use MaskedTextBox1.Text = "999999".
As suggested by tinstaafl in comments, i used a DateTimePicker instead of a MaskedTextBox.
I changed its properties :
CustomFormat = yyyMM
Format = Custom
ShowUpDown = True
This way, i have something similar to a textBox and i can select only the year or only the month and increase it with the up and down buttons.
Related
Well I was wondering whether we can somehow create custom looking text boxes that act as an input box and is linked to VBA.
As far as I am aware the standard procedure would entail adding an ActiveX Textbox Control and then using the TextBox1_Change event to add the code as to what needs to happen when the user enters something in to.
Sadly the look of the default textbox isn't matching the way I want by spreadsheet to look. So is there any way to change how it looks or have something replace it while serving the same purpose?
One thing I could think of and have tried is inserting a shape (blue):
Shape http://im52.gulfup.com/qD2F0B.png
I can get the text that is in the shape using VBA by:
InputText = Shapes("Rounded Rectangle 1").TextFrame.Characters.Text
But I don't suppose there is a way to detect a change of shape text event?
Suggestions / Workarounds are welcome!
Thanks
There are limitations on what you can change on an ActiveX TextBox, such as Font/Color/Border/SpecialEffects, but the basic rectangle shape cannot be changed.
However you can make the TextBox transparent by BackStyle property and group it to a shape (bring the TB forward) and still use the TextBox1_Change method for changes.
If you need to access the value in the TextBox somewhere else, a quick way is to use TextBox1.LinkedCell and below to set the value to a cell, or a Named Range.
Private Sub TextBox1_Change()
' Same Sheet as TextBox1
ActiveSheet.Range(TextBox1.LinkedCell).Value = TextBox1.Value
' Or Below for Named Range
ThisWorkbook.Names(TextBox1.LinkedCell).RefersToRange.Value = TextBox1.Value
End Sub
On a normal textbox, I usually use the AfterUpdate event to perform some action. That means the user has to press Enter or Tab after typing, or click in another control, and I have always been happy with that behaviour.
Now I am setting up a Date filter in the header of a continuous form in Access 2010, and I realize that changing the date through the little calendar that comes automatically, does NOT fire the AfterUpdate event, forcing to press Enter after selecting the correct date, which is a bit heavy.
Using OnChange would trigger at every character entered, which is not nice either.
Any suggestion ?
It is a bit late reply but I hope it will help the others.
When using textbox as a DatePicker you should use Change Event with your filter.
However when you are checking your textbox like Form_name.TextboxName it will show last picked date. To avoid that and use currently selected one you need to provide current date like Form_name.TextboxName.Text. Careful here because .Text property is sensitive to focus.
...in short:
Form_name.TextboxName - will show last picked date
Form_name.TextboxName.Text - will show currently picked date
well, after you select a date from the date-picker, the Change event occurs for the TextBox control. Then, call a sub or function or set focus to another control... to avoid event fires for each pressed key, put something like:
if Len(me.activecontrol) < 10 then exit sub
I hope this helps
I use LostFocus event in the textbox. It allows to use the calendar tool and alter the content. The User has to leave the textbox sooner or later, isn't it?
I use it in this way
Private Sub txt_FirstDate_Change()
txt_FirstDate = txt_FirstDate.Text
myfilter
End Sub
How do I get the value of a textbox in Word?
I know in excel this is the right syntax: ActiveSheet.Shapes(x).Name.
I thought in word this would be the right syntax
ActiveDocument.Shapes(x).Name,
but this doesn't seems to work.
With this piece of code I also couldn't find a textbox:
For i = 1 To ActiveDocument.Shapes.Count
MsgBox ActiveDocument.Shapes(i).Name
Next i
To get the value of a standard textbox, use this:
ActiveDocument.Shapes(1).TextFrame.TextRange.Text
To get the value of ActiveX controls (OLEobjects), use this syntax where TextBox1 is the control name, use
ActiveDocument.TextBox1.Value
To get the name of ActiveX controls, use this:
ActiveDocument.InlineShapes(1).OLEFormat.Object.Name
I used tags (object properties -> assign a tag name) to edit the object's value. Use this syntax to change the value of a content control:
ActiveDocument.SelectContentControlsByTag("Your-Content-Control-Tag").Item(1).Range.Text = "your-preferred-value"
Anyway, thanks Rachel Hettinger for your patience ;).
I have a form with a large number of buttons on it, each named btn1 through btn25. I have another button that is generating a random number and saving it to an integer variable intDrawn.
I'd like to know if there's a simple way to alter a particular button based on the result in intDrawn; if intDrawn = 5, then I want to change the font in btn5, for example.
Is there a way to alter a control programmatically like this? I'm using Visual Basic Express 2008.
It sounds like you'd be better to use a control array. Give your buttons the same name and then use the integer result to change the font for that particular control number in the array.
http://msdn.microsoft.com/en-us/library/kxt4418a%28VS.80%29.aspx - VB6
http://msdn.microsoft.com/en-us/library/aa289500%28VS.71%29.aspx - VB.Net
Create a control array of buttons, and then use the index into this array to alter a particular button.
Control Arrays
There is also a "stupid" way to do this. Add an invisible textbox and after getting your random number you can just text1.text = "btn" + randomnumber, and then change the color or whatever you wish using text1.text.
Control Array is the better choice, but you could also achieve it with reflection.
when DataGridView has a combobox column, how can I get the text it displays as oppose to the value it represents? When I do DGV.Item("cbo",i).Value I get the value but it won't take DGV.Item("cbo",i).Text. I trying Ctype(DGV.Item("cbo",i),ComboBox).Text and this does not work either.
Try
DGV.item("cbo",i).DisplayMember
Umm are you talking about Win Forms?
If so, Value is the property you want, and is what is to be displayed on the screen and held behind the scenes.
If you want something different not shown to the user, I've often used the property Tag for that.
I found this, and the answers didn't work for me. In case someone else finds this, here is what I did.
dgv.rows(i).Cells(cboname.index).EditedFormattedValue
Hope if someone finds this through Google it will help them.
Dim dgvcmbcell As DataGridViewComboBoxCell = DgvItemsUnits.Item("UNIT_SER", 0)
Dim SelectedText As String = dgvcmbcell.EditedFormattedValue.ToString()