Changing text color in a DTPicker control - vb6

In VB6, I have a DTPicker control on a form. (The DTPicker is the calendar date/time selector, included in Microsoft Windows Common Controls-2 6.0, available from the Components dialog.)
While there are many properties to affect the colors of the calendar when it's dropped down, there is no property that allows changing the color of the date that's displayed in the textbox. I'm looking for something like the standard TextBox's ForeColor property.
Does anyone have a little API magic to allow me to simulate that property?

I hate to post something that is not really helpful, but this appears to be something beyond the scope of what Microsoft intended developers to do with the control. While there must certainly be an API call to set the color (Windows certainly knows to paint it black when enabled and gray when disabled), the method to do so escapes me.
My recommendation, should no one else respond with how to do what you need, is to either obtain a new DateTime Picker control with the needed properties (it would seem that there are a few 3rd party options), or "roll your own" control.
FWIW, this same issue exists in VB.NET with the exception being that Microsoft specifically overrides (and then hides) the ForeColor (and BackColor) properties inherited from the generic Control object to do nothing.

I'm going to address two issues with the DatePicker object and a workaround for them.
You cannot put a blank value into DatePicker, which lead me to the 2nd problem.
You cannot change the font color to at least make it appear blank.
To keep the functionality of the DatePicker AND gain the ability to have a blank value and your regular font formatting options (colors, etc), I used two objects. First make a DTP object and set the width so that you can only really see the drop down arrow. For me this was 15. Then make a regular TextBox that is wide enough to hold your date. Put the DTP arrow directly to the right (or left) of the text box. Then you simply add code to the Change event of the DTP to copy its .Value into the .Text of the TextBox like so:
Private Sub MyDTP_Change()
MyUserForm.MyDateTextBox.Text = MyUserForm.MyDTP.Value
End Sub
Then have any data references you need access the MyDateTextBox.Text instead of the MyDTP.Value and presto! You get the functionality of the DTP with the formatting control of a regular TextBox.
EDIT:
Sorry JeffK, I wasn't working with VB in a production environment 9 years ago. :) I would like to add the other side of the functionality to this as well. This allows 2-way syncing between the TextBox and the DTP. IE: Manually enter a date into the TextBox and the DTP Calendar follows. If the TextBox is blank or has an invalid date, the DTP defaults to today's date.
Private Sub MyDateTextBox_Change()
If MyUserForm.MyDateTextBox.Text <> "" And
IsDate(MyUserForm.MyDateTextBox.Text) = True Then
If CDate(MyUserForm.MyDateTextBox.Text) <= MyUserForm.MyDPT.MaxDate And _
CDate(MyUserForm.MyDateTextBox.Text) >= MyUserForm.MyDPT.MinDate Then
MyUserForm.MyDTP.Value = MyUserForm.MyDateTextBox.Text
Else
MyUserForm.MyDTP.Value = Date
End If
Else
MyUserForm.MyDTP.Value = Date
End If
End Sub

Related

Getting the current value of a textbox in Access 2013 Custom Web App

in a List view I want a particular control (textbox) to have a red background color if it has a certain value. I have tried the following:
Click on the textbox then click the Data icon in the context sensitive controls that appear. I can then see that the name of the control is First_NameTextBox. I then click anywhere on the List view and click the Actions icon in the context controls that appear to the right of the view. I select "On Current". I then create two steps that should be executed whenever a new record is activated:
If [First_NameTextBox] = "somevalue" Then
SetProperty
Control Name [First_NameTextBox]
Property BackColor
Value #FF0000
End If
However, this turns the textbox red no matter what the value in First_NameTextBox is. How do I reference the CURRENT value of the textbox?
Conditional formatting based on a field value is not available for the List View in a Web App.
If you've built web pages (with or without a templating engine), the design limitations of Access can be frustrating.
Another kind of frustration comes from moving a form in Access from the native Access environment to a browser-based display.
I've felt the first kind of frustration, but so far I've avoided the second kind. I keep MS Access and HTML-rendered forms far away from each other.
Conditional Formatting in the List View of Access Web Apps is Available its just way harder than it should be.
Input "If Statement" under the "Current Macro" by clicking outside any text box or label then traveling to the top right of the view and you will see the Lightning bolt which allows two options, "On Load" and "On Current".
SELECT ON CURRENT
Don't forget You will need to set the control back to the original color by using the else. (also, for some reason I have to flip the Colors so where you would think red would go, Put White.
Example:
IF = "" True Then
White
Else
Red
END IF /DONT ASK ME WHY!
Summary: your Code is Sound, Just input it under the Views Current Macro Location
This is my first post, i spent DAYS looking for this information and found in the deep google somewhere so i hope this helps you.

How do you create a textbox in visual Studio with c#?

I feel kind of silly asking this question as it seems really simple, but how do I create a text box that I can type in instructions and stuff like that. I don't need the user to be able to change it, it is just to give instructions. I tried the label, but it only allows one line. I need something that can allow about a paragraph or so. Similar to the box in an installer that describes what the program does. What did I miss?
You can use a label but set its AutoSize property to false. This allows you to size the label as you wish and it will automatically wrap the text to fit.
You can also anchor the label to the parent form to have it automatically resize and reflow the text if the user resizes the parent form.
You want a text box, but set its Read Only property to TRUE, and maybe Enabled to FALSE

How can I check the time format entered in a textbox?

I'm using VB 6, and my form has a TextBox control. I want the user to be able to enter the time in the textbox, but I have to validate whether the input time is correct or not.
Example:
Textbox1.Text = 236161 '(User Input)
236161 = HHMMSS
The above entered time is wrong because the minutes and seconds are greater than 60.
What code can I use to check the format of the time entered in the textbox?
I suggest that you use a DTPicker control, instead. This is the date/time picker that is available for VB 6 applications, and it essentially forces the user (but much more gently than that makes it sound) to enter a valid time in the proper format. Trying to do this validation yourself is a giant pain in the rear, and not worth the effort since using a built-in control makes it so much simpler.
You can start using this in your project by following these steps:
In the VB 6 IDE, open the "Project" menu, and then click "Components" (or press Ctrl+T).
Scroll down nearly to the bottom of the list and select "Microsoft Windows Common Controls-2" (preferably version 6.0, if available, rather than version 5.0).
Once you click OK, you will find a handful of new controls added to your toolbox. Find and click on the one called DTPicker. It will look something like this:
Drag the DTPicker control to your form.
Make sure that the control you just added is selected, then in the "Properties" window, scroll down to the "Format" property and set it to "2 - dtpTime". This specifies that you want to accept a time value in the DTPicker control, rather than a date.
With .Net you have regex included. With VB 6 you have to use COM or ActiveX libraries and add them as references to your project (http://www.regexlib.com/DisplayPatterns.aspx?cattabindex=4&categoryId=5 or http://support.microsoft.com/kb/818802)
For samples of regex to check time see: http://www.regexlib.com/DisplayPatterns.aspx?cattabindex=4&categoryId=5
Actually, you can use the format function like this:
TestStr = Format(TestDateTime, "HH:mm:ss")

Disable column in MSHFlexGrid in VB6.0

How do I disable particular columns in MSHFlexgrid in VB6.0? I don't want my user to edit the values in a particular column.
I don't think the MSHFlexGrid control allows users to edit its data in the first place. Therefore, in effect, all columns are disabled. Job done :)
In fact, you have to add custom code to enable updating e.g. add an appropriate control (textbox, combo, date picker, etc) that does allow editing, hide it at design time, then at run time detect which grid cell should have focus, move and size the control to fit the cell then make it visible then handle events to validate the input then write the contents back to the recordset...
...or you could purchase a third party control that does all this out of the box. The MSHFlexGrid that ships with VB6 is essentially a cut-down version of VSFlexGrid Pro, which I've used and thought was quite good. It has a different way of handling hierarchical data by creating groups (rather than bands) which is superior, IMO. The best thing that can be said about the MSHFlexGrid is that it is easy to bind to a hierarchical ADO recordset to simply display the results but not good if you want to do nice formatting or make the grid editable. The VSFlexGrid Pro, if you can afford it, has more power e.g. you can create data source classes to handle binding to custom data structures (ships with VB6 examples of this including ADO recordset binding) which would be invaluable IMO if you intend to make your hierarchical grid editable.
'A Shortcut way is here... NOT in a proper way. But you can try
'if you need to lock the first 3 columns please use this code:
msf2=name of MSFlexGrid
Private Sub msF2_EnterCell()
With msF2
If msF2.Col = 0 Or msF2.Col = 1 Or msF2.Col = 2 Then
msF2.Col = 3
End If
End With
End Sub

Textbox anchored to a form on all 4 sides not displayed properly

I'm running into a problem trying to anchor a textbox to a form on all 4 sides. I added a textbox to a form and set the Multiline property to True and the Anchor property to Left, Right, Up, and Down so that the textbox will expand and shrink with the form at run time. I also have a few other controls above and below the textbox.
The anchoring works correctly in Visual Studio 2005 (i.e. I can resize the form and have the controls expand and shrink as expected), but when I run the project, the bottom of the textbox is extended to the bottom of the form, behind the other controls that would normally appear beneath it. This problem occurs when the form loads, before any resizing is attempted. The anchoring of the textbox is correct for the top, left, and right sides; only the bottom is malfunctioning.
Has anybody heard of this and if so, were you able to find a solution?
Thanks!
UPDATE:
Here is some of the designer code as per Greg D's request (I am only including the stuff that had to do with the textbox itself, not the other controls):
Friend WithEvents txtRecommendationText1 As System.Windows.Forms.TextBox
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.txtRecommendationText1 = New System.Windows.Forms.TextBox
' ...snip...
'txtRecommendationText1
Me.txtRecommendationText1.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.txtRecommendationText1.Location = New System.Drawing.Point(4, 127)
Me.txtRecommendationText1.Multiline = True
Me.txtRecommendationText1.Name = "txtRecommendationText1"
Me.txtRecommendationText1.Size = New System.Drawing.Size(223, 149)
Me.txtRecommendationText1.TabIndex = 10
End Sub
ANOTHER UPDATE:
The textbox I originally posted about was not inherited from a baseclass form (although it was added to a custom User Control class; I probably should have mentioned that earlier), but I recently ran into the same problem on a totally unrelated set of controls that were inherited from a baseclass form. It's easy to blame these problems on possible bugs in the .NET framework, but it's really starting to look that way to me.
Is your Form localized? Check the resource files for an entry with Textbox.Size, delete is and reset the size.
Is your Form inherited and is the Textbox on the baseform? Try setting the Textbox's access modifier to Protected or Public.
Have you implemented custom resize logic? Turn it off and see if the problem is still there.
Have you entered a Textbox.MinimumSize/MaximumSize? Remove or change the value.
It might also be a combination of these things...
Does the form snap back to the expected layout when you resize it after it's been initialized weirdly? Also, have you set a Height or MinimumHeight/MaximumHeight property for the text box?
If possible, a few snippets from the designer code might be useful. :)
One possibility that I've run into in the past is DPI. If you're running/testing your code on a machine with a different DPI setting than the machine that you're developing on, you may observe some strange things.
The anchor functionality essentially establishes a fixed distance between the edge of a control and the edge of the control's parent. Is your textbox embedded within another control (e.g., a panel) that doesn't have its anchors properly set? Right clicking on the text box in the designer should pop up a menu that lets you select any controls that exist underneath it, also.
Does your program include any custom resize logic, or does it modify the size of the textbox programmatically outside of designer-generated code? That might also result in weird behavior. I've assumed maintenance for a number of pieces of software at my organization where the original developers spent a great deal of time implementing (buggy) resize logic that I had to tear out so that I could just let the designer-generated code do the work for me.
The textbox I originally posted about was not inherited from a baseclass form (although it was added to a custom User Control class; I probably should have mentioned that earlier), but I recently ran into the same problem on a totally unrelated set of controls that were inherited from a baseclass form. It's easy to blame these problems on possible bugs in the .NET framework, but it's really starting to look that way to me.
It's very likely because of the 'AutoScaleMode' property being set in InitializeComponent(). Try setting it to 'None' and see if that fixes it. I've had these problem a couple of times now.

Resources