473,729 Members | 2,150 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Newbe question

Jim
I have created a windows form that contains several tab
pages which contain a panels. On a tab page I am trying
to dynamically create a series of buttons in that pages
panel. I am failing because I can not find the proper way
to point to the specific tab page and its panel when
creating the buttons.

I also need to dynamically change the background color
property of each button as it is clicked.

I can dynamically create the buttons in a blank form with
the code below, but am unable to create them in the tab
page-panel and I can not dynamically change the
background color within my click event.

Any help would be greatly appreciated.

Code is below (I used the sample on the net for the
structure):

This is fired from a click event in a statically placed
button.

For sX = 0 To 5
Dim bX As New Button
bX.Name = "Level" + m_controlCount. ToString
bX.Text = "C" + m_controlCount. ToString
bX.Width = 60
bX.Height = 20
bX.Location = New Point(m_Locatio n.X + 70,
m_Location.Y)
m_Location.X += 65

AddHandler bX.Click, AddressOf
LevelHandler_Cl ick
AddHandler bX.MouseHover, AddressOf
LevelHandler_Mo useHover

Controls.Add(bX )
m_controlCount += 1
bX.Visible = True

Next sX

Here is the LevelHandler code that does not work. The
entire form changes color:

Private Sub LevelHandler_Cl ick(ByVal sender As
System.Object, ByVal e As EventArgs)
If TypeOf sender Is Button Then
If System.Drawing. ColorTranslator .ToOle
(Button.Default BackColor) =
System.Drawing. ColorTranslator .ToOle
(System.Drawing .Color.Red) Then

BackColor =
System.Drawing. ColorTranslator .FromOle(&H8000 000F)
Else
BackColor = System.Drawing. Color.Red
End If
End If
End Sub

Nov 20 '05 #1
1 2020
Hi Jim,
To add the buttons to the panel, you need to add it to the Panel's control
collection. In the code below you are adding them to the form since the
form's properties are exposed by default.

The one line of code you need to change is from this:
Controls.Add(bX )
To this:
MyPanel.Control s.Add(bX)

This is the same problem you are facing with the changing color. Simply
using BackColor = System.Drawing. Color.Red sets the form's backcolor to
red. To set the button's backcolor, you need to specifically say:
Sender.BackColo r=System.Drawin g.Color.Red

BackColor won't show up in intellisense on Sender since it is of type
object but it is valid in the case below since you make sure that Sender is
of type button. If you did want intellisense, you could cast the sender to
a button.

Hope that helps,
Eric
VB.Net team

--------------------
| Content-Class: urn:content-classes:message
| From: "Jim" <jh***@cox.ne t>
| Sender: "Jim" <jh***@cox.ne t>
| Subject: Newbe question
| Date: Wed, 22 Oct 2003 10:51:39 -0700
|
| I have created a windows form that contains several tab
| pages which contain a panels. On a tab page I am trying
| to dynamically create a series of buttons in that pages
| panel. I am failing because I can not find the proper way
| to point to the specific tab page and its panel when
| creating the buttons.
|
| I also need to dynamically change the background color
| property of each button as it is clicked.
|
| I can dynamically create the buttons in a blank form with
| the code below, but am unable to create them in the tab
| page-panel and I can not dynamically change the
| background color within my click event.
|
| Any help would be greatly appreciated.
|
| Code is below (I used the sample on the net for the
| structure):
|
| This is fired from a click event in a statically placed
| button.
|
| For sX = 0 To 5
| Dim bX As New Button
| bX.Name = "Level" + m_controlCount. ToString
| bX.Text = "C" + m_controlCount. ToString
| bX.Width = 60
| bX.Height = 20
| bX.Location = New Point(m_Locatio n.X + 70,
| m_Location.Y)
| m_Location.X += 65
|
| AddHandler bX.Click, AddressOf
| LevelHandler_Cl ick
| AddHandler bX.MouseHover, AddressOf
| LevelHandler_Mo useHover
|
| Controls.Add(bX )
| m_controlCount += 1
| bX.Visible = True
|
| Next sX
|
| Here is the LevelHandler code that does not work. The
| entire form changes color:
|
| Private Sub LevelHandler_Cl ick(ByVal sender As
| System.Object, ByVal e As EventArgs)
| If TypeOf sender Is Button Then
| If System.Drawing. ColorTranslator .ToOle
| (Button.Default BackColor) =
| System.Drawing. ColorTranslator .ToOle
| (System.Drawing .Color.Red) Then
|
| BackColor =
| System.Drawing. ColorTranslator .FromOle(&H8000 000F)
| Else
| BackColor = System.Drawing. Color.Red
| End If
| End If
| End Sub
|
|

Nov 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
1844
by: WindAndWaves | last post by:
Hi Gurus I hope I am going to make sense with this question: I have an html page that I have turned into a php page with a bit of php code above the html (connect to database, massage data a little, mix with html, etc...). Now, I would like to use a function in my php code, as otherwise I have to type the same thing over and over again. With a function, I mean something along of the lines of: function x($string) { return...
1
1658
by: Sebastien GIRAUD | last post by:
Hello, First let say that am french and that i'll try to write the best english i can... I'm a python newbe and have the following problem : I try to create 2 threads in a server program and they seems to block each other. I use something like this : start thread waiting for connexion with : server.threadserver = threading.Thread(target = self.__startserver) then do while 1 : socket, host = accept(...) then start a new thread for each new...
1
1783
by: Ron | last post by:
Is this built into any of the python versions? Need it! Using 2.3.5 and doesn't seem to have it.Newbe needs help!email ron@nac.net Thanks Ron
7
1888
by: Jean Pierre Daviau | last post by:
Hi, <script language="javascript" type="text/javascript"> if(navigator.appName.indexOf("Netscape") != -1){ document.writeln('<link rel="stylesheet" href="~styles/aquarelle_ns.css" type="text/css" media="screen" title="base" />'); }else{ document.write('<link rel="stylesheet" href="~styles/aquarelle.css" type="text/css" media="screen" title="base" />'); }
9
6688
by: Yaro | last post by:
Hello DB2/NT 8.1.3 Sorry for stupid questions. I am newbe in DB2. 1. How can I read *.sql script (with table and function definitions) into a database? Tool, command... 2. In Project Center I created funcion CREATE FUNCTION DB2ADMIN.xxx( )
6
1489
by: ken | last post by:
Hi all, I copied this code from the examples. "How to: Receive Strings From Serial Ports in Visual Basic" When I call the function and using the single step method it hangs at Dim Incoming As String = com1.ReadLine(). I don't have anything connect to Comm1. Does anyone know why this is happening? Thanks for the help. Regards, Ken Function ReceiveSerialData() As String ' Receive strings from a serial port.
19
1547
by: AMP | last post by:
I have a simple question. If i have a button on form1 that creates : Form2 newform = new Form2(); newform.Show(); As I click the button a new form shows,but acording to my code each one has the same name.Are they really there(I can move them around and close them).If they are how do they have the same name (to refer to in code).
17
2716
by: Eric_Dexter | last post by:
def simplecsdtoorc(filename): file = open(filename,"r") alllines = file.read_until("</CsInstruments>") pattern1 = re.compile("</") orcfilename = filename + "orc" for line in alllines: if not pattern1 print >>orcfilename, line I am pretty sure my code isn't close to what I want. I need to be able
13
1722
by: Eric_Dexter | last post by:
All I am after realy is to change this reline = re.line.split('instr', '/d$') into something that grabs any line with instr in it take all the numbers and then grab any comment that may or may not be at the end of the line starting with ; until the end of the line including white spaces.. this is a corrected version from http://python-forum.org/py/viewtopic.php?t=1703
0
8761
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9426
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9142
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8144
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6016
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4795
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2677
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2162
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.