Button in the Title Bar

  • Thread starter Thread starter Jerry Camel
  • Start date Start date
J

Jerry Camel

Is there an easy way to create a button in the title bar in VB .NET?
Thanks.

Jerry
 
Considering the title bar is nothing more than a text property... Not
really... however, this doesn't mean you can't create a quick and dirty
function to do it...

I would do something like

private _handlerCreated as boolean

private sub putCtlinTitleBar(ctl as system.windows.forms.control, optional
xoffset as integer = 5)

ctl.location = new System.Drawing.Point (me.left + xoffset, me.top)

if not (_handlerCreated) then
AddHandler me.SizeChanged, new EventHandler (AddressOf
myHandleFunction)
AddHandler me.LocationChanged, new EventHandler (AddressOf
myHandleFunction)
_handlerCreated = true
end if

end sub

By adding the event handlers you will automatically adjust for movement in
the form. And considering your button will "probably" be created a design
time, it will be disposed when the form is closed.

The _handleCreated is important, because you will just keep adding them,
which will just keep getting bigger and keep calling the event every time it
changes... Performance will be a problem =)

The handle function will move the button as needed... Just program it just
like the first function, or do it all in there... doesn't matter. =) This
is just an example of course. But I've done this with user controls before
and works great.

-CJ
 
Back
Top