Custom control won't expand outside table

robertza

New member
Joined
Aug 30, 2006
Messages
2
Location
Auckland
Programming Experience
1-3
Hi

I'm in the process of developing my own date time picker similar to the standard VB control (except, this one is nullable). The control consits of a masked text box, a button and a calendar control.

The calendar control is hidden by default and the form is shrunk to just display the text box and button. When the button is pushed the form is resized and the calendar set to visible. Once the date is selected the reverese happens and the calendar is again hidden.

Everything seems to be working pretty well until I place my new control in a Table Layout Panel. When I now click the button my calendar does not appear. I guess this has something to do with the height of the table row.

How do I allow the calendar control to be drawn outside the row my control is in? (As with the default date time picker).

Thanks
 
To be honest this isn't a good design for a custom control. Constant resizing and such can lead to problems as you have found out. If you don't mind me saying you would be better off just creating a dropdown section for your control.
Take a look at the link below. It is a thread on these forums where i created a simple 'combobox like' drop down section for a button, the thing is that the drop down part uses a form, so that means that you could code it to hold your datetime picker control and you wouldn't experience the present problems you have.

http://www.vbdotnetforums.com/showthread.php?t=12081
 
Thanks Vis781

I've downloaded your code and I just have one or 2 questions. I'm not to clued up on the paint methods yet, so I guess I'll have to spend a little time going through everything.

How do I add the control to the drop down form. Just sticking the control on the form doesn't work and neither does adding a control programmatically.

VB.NET:
Expand Collapse Copy
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Protected[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Overrides[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] OnPaintBackground([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] pevent [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Windows.Forms.PaintEventArgs)[/SIZE]
[SIZE=2][COLOR=#0000ff] MyBase[/COLOR][/SIZE][SIZE=2].OnPaintBackground(pevent)[/SIZE]
[SIZE=2] pevent.Graphics.Clear(SystemColors.ActiveCaptionText)[/SIZE]
[SIZE=2][COLOR=#0000ff] Dim[/COLOR][/SIZE][SIZE=2] rect [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Rectangle = [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].ClientRectangle[/SIZE]
[SIZE=2] rect.Width -= 1[/SIZE]
[SIZE=2] rect.Height -= 1[/SIZE]
[SIZE=2] pevent.Graphics.DrawRectangle(SystemPens.WindowText, rect)[/SIZE]
[SIZE=2] pevent.Graphics.DrawString([/SIZE][SIZE=2][COLOR=#800000]"PAINTCustom DropDown Menu, Add Control Here"[/COLOR][/SIZE][SIZE=2], _[/SIZE]
[SIZE=2][COLOR=#0000ff] New[/COLOR][/SIZE][SIZE=2] Font([/SIZE][SIZE=2][COLOR=#800000]"Times New Roman"[/COLOR][/SIZE][SIZE=2], 16, FontStyle.Bold, GraphicsUnit.Pixel), _[/SIZE]
[SIZE=2] SystemBrushes.WindowText, 1, 1)[/SIZE]
[SIZE=2][COLOR=#008000] 'I guess the calendar control should be added here, but I'm not quite sure how[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
[/COLOR][/SIZE]

Once again, thanks for the advice and help.
 
No, you don't want to add the control in the paint event. Your best bet is to add it in the popup constructor. Create it there and set its size and location etc....

Then the paintbackground sub shoud look like this.

VB.NET:
Expand Collapse Copy
 [LEFT]ProtectedOverridesSub OnPaintBackground(ByVal pevent As System.Windows.Forms.PaintEventArgs)
MyBase.OnPaintBackground(pevent)
pevent.Graphics.Clear(SystemColors.ActiveCaptionText)
Dim rect As Rectangle = Me.ClientRectangle
rect.Width -= 1
rect.Height -= 1
pevent.Graphics.DrawRectangle(SystemPens.WindowText, rect)
EndSub
[/LEFT]
 
Back
Top