Hi,
I am trying to create a form and add some controls to it programmatically. I
am pasting the code I have so far, below. here are the issues I am having.
#1. I am having to subtract additional 35 points from the
closeAbuotButton.Top ot the control goes out of form's bounds. I have no
clue why.
#2. I do not know how to access my Close Button's click event. It is asking
me to create "WithEvents" but I can't figure our where/how to use it.
Thank you.
'Code still not working...
Private Sub aboutHelpMenuItem_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles aboutHelpMenuItem.Click
'Create and Display About Dialog.
Dim nameLabel As New Label
Dim messageLabel As New Label
aboutForm = New Form
'Create Form
With aboutForm
.Text = "About"
.FormBorderStyle = FormBorderStyle.FixedDialog
.Height = 150
.Width = 300
'.ControlBox = False
End With
'Add Message Label
aboutForm.Controls.Add(messageLabel)
With messageLabel
.Text = "Programmed by Me"
.Top = 5
.Left = 5
.Width = aboutForm.Width - 5
.Height = 20
.TextAlign = ContentAlignment.MiddleCenter
End With
'Add Close Button
aboutForm.Controls.Add(closeAboutButton)
With closeAboutButton
.Hide()
.Text = "&Close"
.Width = 100
.Height = 25
.Top = aboutForm.Height - closeAboutButton.Height - 35 'For some reason
if I do not have -35, control goes out of form's bounds.
.Left = (aboutForm.Width / 2) - (closeAboutButton.Width / 2)
.Show()
End With
aboutForm.ShowDialog()
End Sub
Private Sub closeAboutButton_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles closeAboutButton.Click
'Close Form
Me.Close()
End Sub 7 1551
Dragon wrote: Hi,
I am trying to create a form and add some controls to it programmatically. I am pasting the code I have so far, below. here are the issues I am having.
#1. I am having to subtract additional 35 points from the closeAbuotButton.Top ot the control goes out of form's bounds. I have no clue why. #2. I do not know how to access my Close Button's click event. It is asking me to create "WithEvents" but I can't figure our where/how to use it.
Thank you.
'Code still not working... Private Sub aboutHelpMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles aboutHelpMenuItem.Click 'Create and Display About Dialog.
Dim nameLabel As New Label Dim messageLabel As New Label aboutForm = New Form
'Create Form With aboutForm .Text = "About" .FormBorderStyle = FormBorderStyle.FixedDialog .Height = 150 .Width = 300 '.ControlBox = False End With
'Add Message Label aboutForm.Controls.Add(messageLabel) With messageLabel .Text = "Programmed by Me" .Top = 5 .Left = 5 .Width = aboutForm.Width - 5 .Height = 20 .TextAlign = ContentAlignment.MiddleCenter End With
'Add Close Button aboutForm.Controls.Add(closeAboutButton) With closeAboutButton .Hide() .Text = "&Close" .Width = 100 .Height = 25 .Top = aboutForm.Height - closeAboutButton.Height - 35 'For some reason if I do not have -35, control goes out of form's bounds. .Left = (aboutForm.Width / 2) - (closeAboutButton.Width / 2) .Show() End With
aboutForm.ShowDialog()
End Sub
Private Sub closeAboutButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles closeAboutButton.Click 'Close Form Me.Close() End Sub
You dont' show the code where you create closeAboutButton, but the
declare needs to look like
dim WithEvents Variable as ObjectType
This gives you to hook into events of the object.
As for why you have to -35 off the top. This is because of the border
and Title bar. If you just want the inside height of the form use this.
..Top = aboutForm.ClientSize.Height - closeAboutButton.Height
Hope it helps
Chris
"Dragon" <ba***********@hotmail.com> schrieb: #2. I do not know how to access my Close Button's click event. It is asking me to create "WithEvents" but I can't figure our where/how to use it.
Take a look at the documentation for the 'AddHandler' statement. You can
use this statement to dynamically add an event handler:
\\\
AddHandler btn.Click, AddressOf Me.Button_Click
///
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Thank you for your reply.
I have tried dimming the button like:
Dim WithEvents closeAboutButton As Button
but I get an error saying "WithEvents" is not valid on a local veriable
declaration.
Any ideas?
"Chris" <no@spam.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl... Dragon wrote: Hi,
I am trying to create a form and add some controls to it programmatically. I am pasting the code I have so far, below. here are the issues I am having.
#1. I am having to subtract additional 35 points from the closeAbuotButton.Top ot the control goes out of form's bounds. I have no clue why. #2. I do not know how to access my Close Button's click event. It is asking me to create "WithEvents" but I can't figure our where/how to use it.
Thank you.
'Code still not working... Private Sub aboutHelpMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles aboutHelpMenuItem.Click 'Create and Display About Dialog.
Dim nameLabel As New Label Dim messageLabel As New Label aboutForm = New Form
'Create Form With aboutForm .Text = "About" .FormBorderStyle = FormBorderStyle.FixedDialog .Height = 150 .Width = 300 '.ControlBox = False End With
'Add Message Label aboutForm.Controls.Add(messageLabel) With messageLabel .Text = "Programmed by Me" .Top = 5 .Left = 5 .Width = aboutForm.Width - 5 .Height = 20 .TextAlign = ContentAlignment.MiddleCenter End With
'Add Close Button aboutForm.Controls.Add(closeAboutButton) With closeAboutButton .Hide() .Text = "&Close" .Width = 100 .Height = 25 .Top = aboutForm.Height - closeAboutButton.Height - 35 'For some reason if I do not have -35, control goes out of form's bounds. .Left = (aboutForm.Width / 2) - (closeAboutButton.Width / 2) .Show() End With
aboutForm.ShowDialog()
End Sub
Private Sub closeAboutButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles closeAboutButton.Click 'Close Form Me.Close() End Sub
You dont' show the code where you create closeAboutButton, but the declare needs to look like
dim WithEvents Variable as ObjectType
This gives you to hook into events of the object.
As for why you have to -35 off the top. This is because of the border and Title bar. If you just want the inside height of the form use this.
.Top = aboutForm.ClientSize.Height - closeAboutButton.Height
Hope it helps Chris
Thank you Herfried. I will have to look into this for sure.
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:uJ**************@tk2msftngp13.phx.gbl... "Dragon" <ba***********@hotmail.com> schrieb: #2. I do not know how to access my Close Button's click event. It is asking me to create "WithEvents" but I can't figure our where/how to use it.
Take a look at the documentation for the 'AddHandler' statement. You can use this statement to dynamically add an event handler:
\\\ AddHandler btn.Click, AddressOf Me.Button_Click ///
-- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/>
Dragon wrote: Thank you for your reply.
I have tried dimming the button like:
Dim WithEvents closeAboutButton As Button
but I get an error saying "WithEvents" is not valid on a local veriable declaration.
Any ideas?
"Chris" <no@spam.com> wrote in message news:%2****************@TK2MSFTNGP12.phx.gbl...
Dragon wrote:
Hi,
I am trying to create a form and add some controls to it programmatically. I am pasting the code I have so far, below. here are the issues I am having.
#1. I am having to subtract additional 35 points from the closeAbuotButton.Top ot the control goes out of form's bounds. I have no clue why. #2. I do not know how to access my Close Button's click event. It is asking me to create "WithEvents" but I can't figure our where/how to use it.
Thank you.
'Code still not working... Private Sub aboutHelpMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles aboutHelpMenuItem.Click 'Create and Display About Dialog.
Dim nameLabel As New Label Dim messageLabel As New Label aboutForm = New Form
'Create Form With aboutForm .Text = "About" .FormBorderStyle = FormBorderStyle.FixedDialog .Height = 150 .Width = 300 '.ControlBox = False End With
'Add Message Label aboutForm.Controls.Add(messageLabel) With messageLabel .Text = "Programmed by Me" .Top = 5 .Left = 5 .Width = aboutForm.Width - 5 .Height = 20 .TextAlign = ContentAlignment.MiddleCenter End With
'Add Close Button aboutForm.Controls.Add(closeAboutButton) With closeAboutButton .Hide() .Text = "&Close" .Width = 100 .Height = 25 .Top = aboutForm.Height - closeAboutButton.Height - 35 'For some reason if I do not have -35, control goes out of form's bounds. .Left = (aboutForm.Width / 2) - (closeAboutButton.Width / 2) .Show() End With
aboutForm.ShowDialog()
End Sub
Private Sub closeAboutButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles closeAboutButton.Click 'Close Form Me.Close() End Sub
You dont' show the code where you create closeAboutButton, but the declare needs to look like
dim WithEvents Variable as ObjectType
This gives you to hook into events of the object.
As for why you have to -35 off the top. This is because of the border and Title bar. If you just want the inside height of the form use this.
.Top = aboutForm.ClientSize.Height - closeAboutButton.Height
Hope it helps Chris
You must declare the button on the form level for it to work, not inside
a sub or function.
Chris
"Dragon" <ba***********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl... I am trying to create a form and add some controls to it programmatically.
#1. I am having to subtract additional 35 points from the closeAbuotButton.Top ot the control goes out of form's bounds.
Form.Height and .Width describe the Form /overall/, including
the borders and menubars.
Try using ClientArea.Height and .Width instead.
#2. I do not know how to access my Close Button's click event. It is asking me to create "WithEvents" but I can't figure our where/how to use it.
As you add each Control, use the AddHandler statement to
"wire up" the Events you're interested in to routines that can process
them, as in ...
Private Sub AnyButton_Click( sender as Object, e as EventArgs )
. . .
End Sub
.... then ...
x = New Button
AddHandler x.Click, AddressOf AnyButton_Click
HTH,
Phill W.
Thank you Phil.
"Phill. W" <P.A.Ward@o-p-e-n-.-a-c-.-u-k> wrote in message
news:dj**********@yarrow.open.ac.uk... "Dragon" <ba***********@hotmail.com> wrote in message news:%2****************@TK2MSFTNGP15.phx.gbl...
I am trying to create a form and add some controls to it programmatically.
#1. I am having to subtract additional 35 points from the closeAbuotButton.Top ot the control goes out of form's bounds.
Form.Height and .Width describe the Form /overall/, including the borders and menubars.
Try using ClientArea.Height and .Width instead.
#2. I do not know how to access my Close Button's click event. It is asking me to create "WithEvents" but I can't figure our where/how to use it.
As you add each Control, use the AddHandler statement to "wire up" the Events you're interested in to routines that can process them, as in ...
Private Sub AnyButton_Click( sender as Object, e as EventArgs ) . . . End Sub
... then ...
x = New Button AddHandler x.Click, AddressOf AnyButton_Click
HTH, Phill W.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Ben |
last post by:
My current project requires me to create part of a form that is
created on the fly. The project consists a list of entries to an
event. The name and address and such is easy. The design is detup so...
|
by: Anand Sagar |
last post by:
I have a Panel1 and button1 on my webform. At runtime, I create 2 textboxes.
I do it at the Page_Load event. I put the code within the " If Not
isPostBack"
For the button click event, I will do...
|
by: Glenn Owens |
last post by:
I have an ASP.Net page on which there are serveral static controls
(listboxes, radiobuttonlist and textboxes). These controls are used to
create criteria from which the code-behind will dynamically...
|
by: Patrick |
last post by:
I want to define a set of web-form templates in XML and render the equivalent
web-form with ASP.NET, then process any input server controls on the form.
Reading the XML file from Page_load is...
|
by: scsharma |
last post by:
Hi,
I am working on creating a webapplication and my design calls for creating
main webform which will have menu bar on left hand side and a IFrame which
will contain all the forms that are shown...
|
by: Mats Lycken |
last post by:
Hi,
I'm creating a CMS that I would like to be plug-in based with different
plugins handling different kinds of content.
What I really want is to be able to load/unload plugins on the fly
without...
|
by: bill |
last post by:
I'm using VS2005.
I am dynamically adding a Textbox control to a Placeholder control in the
page_load event of the form, but the event handler isn't firing. What am I
doing wrong?
Thanks...
|
by: Scott McNair |
last post by:
Hi,
I'm creating a user control that has absolutely no visual pieces to it...
it's essentially a piece that sniffs a serial port awaiting incoming data.
I know that there are several controls...
|
by: jehugaleahsa |
last post by:
Hello:
We are implementing a work flow system. We would like there to be one
site hosting all the different work flows. Each state in the work flow
is to be associated with a web user control...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |