To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
VBForums  

VB Wire News
Part 10 of the Visual Basic .NET 2010 Express Tutorial Complete!
How to Use the Visual Studio Code Analysis Tool FxCop
Article :: Interview with Andrei Alexandrescu (Part 3 of 3)
Introducing Visual Studio LightSwitch
Visual Studio LightSwitch Beta 1 is Available



Go Back   VBForums > Visual Basic > Visual Basic .NET

Reply Post New Thread
 
Thread Tools Display Modes
Old Jun 19th, 2007, 05:14 PM   #1
blakemckenna
PowerPoster
 
Join Date: Jan 04
Posts: 2,838
blakemckenna is on a distinguished road (10+)
Resolved [RESOLVED] Changing colors of an Object and inserting into another Object???

I'm dynamically creating controls and inserting them into a Panel. My problem is that I'm creating a Checkbox control (setting various properties) and then a Label control (setting various properties). I wish for the text for each of the controls to be Black and Red respectively. They are to be right beside each other with a blank space separating them. The code I have provided does this if the for loop contains 1 iteration. If their are more than 1 iteration, the Red Asterisk doesn't show up. I've tried adding spaces between each occurrence of the checkbox and it still won't show up. Anyway, here is my code:
Code:
            If resp Is Nothing Then
                Dim asterisk As New Label
                asterisk.Text = "*"
                For Each row As DataRow In ds2.Tables(0).Rows
                    Dim chk As New CheckBox
                    chk.AutoSize = True
                    chk.Top = 7
                    chk.BackColor = pnl1.BackColor
                    chk.ForeColor = Color.Black
                    chk.TextAlign = ContentAlignment.MiddleLeft
                    chk.Text = row("labelName")
                    chk.Left = tmpWidth
                    Me.pnl2.Controls.Add(chk)
                    If row("required") = "Y" Then
                        asterisk.Top = chk.Top
                        asterisk.Left = chk.Width
                        asterisk.ForeColor = Color.Red
                        Me.pnl2.Controls.Add(asterisk)
                        tmpWidth = tmpWidth + chk.Width + 25
                    Else
                        tmpWidth = tmpWidth + chk.Width
                    End If
                    AddHandler chk.Click, AddressOf CheckBox1_Click
                Next
           End If
__________________
Blake
blakemckenna is offline   Reply With Quote
Old Jun 19th, 2007, 05:26 PM   #2
techgnome
Snarky...
 
techgnome's Avatar
 
Join Date: May 02
Posts: 15,476
techgnome has a brilliant future (2000+)techgnome has a brilliant future (2000+)techgnome has a brilliant future (2000+)techgnome has a brilliant future (2000+)techgnome has a brilliant future (2000+)techgnome has a brilliant future (2000+)techgnome has a brilliant future (2000+)techgnome has a brilliant future (2000+)techgnome has a brilliant future (2000+)techgnome has a brilliant future (2000+)techgnome has a brilliant future (2000+)
Re: Changing colors of an Object and inserting into another Object???

sooo.... you need a label with an asterisk in it and a check box... for each row? right?
Seems to me then, your label would need to be created inside your loop... not outside...

-tg
__________________
* I don't respond to private requests for help. It's not conducive to the general learning of others.-I also subscribe to all threads I participate, so there's no need to pm when there's an update.*
* How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
* How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to???
* On Error Resume Next is error ignoring, not error handling(tm). * Use Offensive Programming, not Defensive Programming.
"There is a major problem with your code, and VB wants to tell you what it is.. but you have decided to put your fingers in your ears and shout 'I'm not listening!'" - si_the_geek on using OERN
MVP '06-'10
techgnome is offline   Reply With Quote
Old Jun 19th, 2007, 06:01 PM   #3
blakemckenna
PowerPoster
 
Join Date: Jan 04
Posts: 2,838
blakemckenna is on a distinguished road (10+)
Re: Changing colors of an Object and inserting into another Object???

If the For Loop has 1 iteration....the code does what it is supposed to do. The problem is when there are more than 1 iterations of the Loop. I think it has to do with the spacing between each CheckBox. The Asterisk is placed on the right side of the checkbox....so, it would seem that the subsequent checkboxes are overlaying the position of the Asterisk....but I can't be sure of that because I have tried incrementing the space between each checkbox and the asterisk still won't appear.
__________________
Blake
blakemckenna is offline   Reply With Quote
Old Jun 19th, 2007, 07:30 PM   #4
jmcilhinney
.NUT
 
jmcilhinney's Avatar
 
Join Date: May 05
Location: Sydney, Australia
Posts: 61,544
jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)
Re: Changing colors of an Object and inserting into another Object???

I'd suggest that you use a TableLayoutPanel. You simply set the number of columns to two and just alternately add the controls. The TLP will automatically grow to the appropriate number of rows.
__________________

2007-2010

Why is my data not saved to my database? | Communicating between multiple forms | MSDN Data Walkthroughs
MSDN "How Do I?" Videos: VB | C#
VBForums Database Development FAQ
My CodeBank Submissions: VB (Nullable Data Extensions *NEW*) (Serial Code TextBox *NEW*) | C# (ForumAccount has translated some of my VB submissions to C#)
My Blog: Defining and Raising Custom Events | Using Parameters in ADO.NET | Keyboard Events *NEW*
jmcilhinney is online now   Reply With Quote
Old Jun 19th, 2007, 07:31 PM   #5
Bulldog
Frenzied Member
 
Bulldog's Avatar
 
Join Date: Jun 05
Location: South UK
Posts: 1,653
Bulldog is a jewel in the rough (300+)Bulldog is a jewel in the rough (300+)Bulldog is a jewel in the rough (300+)Bulldog is a jewel in the rough (300+)
Re: Changing colors of an Object and inserting into another Object???

As techgnome suggests the label should be defined in the loop and also
Code:
asterisk.Left = chk.Width
should be
Code:
asterisk.Left = chk.Right
Here is my test case (which is butchered from your code, so you cannot directly replace your code with this)...

Code:
        Dim tmpwidth As Integer = 0
        Dim asterisk As Label
        For i As Integer = 0 To 5
            asterisk = New Label
            asterisk.AutoSize = True
            asterisk.Text = "*"
            Dim chk As New CheckBox
            chk.AutoSize = True
            chk.Top = 7
            chk.BackColor = Me.BackColor
            chk.ForeColor = Color.Black
            chk.TextAlign = ContentAlignment.MiddleLeft
            chk.Text = i.ToString
            chk.Left = tmpwidth
            Me.Controls.Add(chk)
            If "Y" = "Y" Then
                asterisk.Top = chk.Top
                asterisk.Left = chk.Right
                asterisk.ForeColor = Color.Red
                Me.Controls.Add(asterisk)
                tmpwidth = tmpwidth + chk.Width + 25
            Else
                tmpwidth = tmpwidth + chk.Width
            End If
        Next
EDIT: If you use a TLP as JM suggests then you don't need to worry about the positions.
__________________

  • If my post helped you, please Rate it
  • If your problem is solved please also mark the thread resolved
I use VS2005/8 Standard (unless otherwise stated).
_________________________________________________________________________________
B.Sc(Hons), AUS.P, C.Eng, MIET, MIEEE, MBCS / MCSE+Sec, MCSA+Sec, MCP, A+, Net+, Sec+, MCIWD, CIWP, CIWA
I wrote my very first program in 1975, using machine code on a mechanical Olivetti teletype connected to an 8-bit, 78 instruction, 1MHz, Motorola 6800 multi-user system with 2k of memory. Using Windows, I dont think my situation has improved.

Last edited by Bulldog; Jun 19th, 2007 at 07:36 PM.
Bulldog is offline   Reply With Quote
Old Jun 20th, 2007, 09:08 AM   #6
blakemckenna
PowerPoster
 
Join Date: Jan 04
Posts: 2,838
blakemckenna is on a distinguished road (10+)
Re: Changing colors of an Object and inserting into another Object???

Thanks guys...that worked!
__________________
Blake
blakemckenna is offline   Reply With Quote
Reply

Go Back   VBForums > Visual Basic > Visual Basic .NET


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 05:37 AM.





Acceptable Use Policy

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.