Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Few newbie questions on WinForms
Message
From
08/03/2008 11:53:43
 
General information
Forum:
ASP.NET
Category:
Forms
Environment versions
OS:
Windows XP
Miscellaneous
Thread ID:
01299299
Message ID:
01299994
Views:
12
This message has been marked as a message which has helped to the initial question of the thread.
Even if you're just playing around, start out by sub-classing the controls. Yeah, there's some threads around here somewhere that talk about how to do it, but here's a little blurb that I always post when asked about it:

Basically, you'll want a class library that contains your sub-classed UI controls, like textbox, button, etc. Something like this:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace MyCompany.MyFramework.WinUI.MyClasses
{
	public class MyComboBox : System.Windows.Forms.ComboBox
	{
		// code here
	}

	public class MyTextBox : System.Windows.Forms.TextBox
	{
		// code here
	}

	public class MyButton : System.Windows.Forms.Button
	{
		// code here
	}
}
That's it. These controls can't be sub-classed visually, but as you can see, it's easy enough to do it in code. I have all the basic controls sub-classed in one class library file. Once they're added to the ToolBox, then can be dragged onto any design surface in the IDE.

~~Bonnie




>Hi Bonnie,
>
>Thanks a lot for taking time to respond.
>
>>Naomi,
>>
>>I notice that no one has replied to this post. Possibly because you ask 3 totally un-related questions in one post. You might make it easier for everyone, yourself included, to have only question per thread.
>>
>>>1) I don't see a Tooltip property for the textbox. My textbox may not hold the whole value, so my question is - what should I do to make a tooltip text to show the whole value in the textbox in cases when the length of it is not enough?
>>
>>In the your TextBox sub-class (you *are* sub-classing controls, right?), you can add a ToolTip:
>>
>>
>>        protected ToolTip oToolTip;
>>
>>	public MyTextBox()
>>        {
>>	    this.MouseEnter += new EventHandler(MouseEnterHandler);
>>            this.oToolTip = new ToolTip();
>>        }
>>        protected virtual void MouseEnterHandler(object sender, System.EventArgs e)
>>        {
>>            this.oToolTip.SetToolTip(this, this.Text);
>>        }
>>
>
>Honestly, no, I haven't yet started creating my controls, I was using them directly from the toolbox. I would need to research on how to create controls and place them on the toolbox (AFAIK it was discussed here too, I need to review one day).
>
>But I found tooltip in another group of controls, added it to the form and all controls started to show tooltip property.
>
>I didn't figure out how to make it dynamic, though, and know when to show it, if the field length is not long enough.
>
>>
>>
>>>2) I don't really like the MS DatePicker. I want a date textbox and a little button to show the calendar and pick the date. What would you suggest me to use here?
>>
>>Nobody likes the MS date controls. We created one almost 6 years ago to overcome the deficiencies of the MS controls (a date text box, a calendar button and a time text box). I cannot reproduce it here, it's long and involved and complex, plus it's company property (they probably wouldn't like it). But a Google search might turn up something useful.
>
>I'll do search. Basically this is what I implemented myself (masked textbox, button and a MonthlyView control, but I found problems, so I would really need to google something better - yesterday I just wanted to finish it quickly, since it was just a little helper app - but I could not get it to my liking and spent too much time trying to perfect something too imperfect to begin with.
>
>>
>>>3) I have a texbox to type the name of the file to save the results into. I'm thinking of using SaveDialog, but I also want to be able to plainly type in the textbox without any dialogs. I'm thinking what would be a good approach here? Add this dialog invocation in the GotFocus of the textbox? What do you think?
>>
>>Not a good idea in the GotFocus ... probably just a button next to the TextBox (you know, one with an ellipsis ...)
>>
>>~~Bonnie
>
>Yes, I finally decided to just keep the textbox and add a prompt in the procedure code in case the textbox was left empty. BTW, when I first tried my idea with the GotFocus, I did crash VS <g>
>>
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform