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
MSDN Subscribers: Download the VS 2010 Release Candidate
MSDN Subscribers: Download the VS 2010 Release Candidate
Sell Your Code and Make Money?
Creating your own Tetris game using VB.NET
Article :: Improving Software Economics, Part 4 of 7: Top 10 Principles of Iterative Software Management



Go Back   VBForums > Visual Basic > Visual Basic .NET

Reply Post New Thread
 
Thread Tools Search this Thread Display Modes
Old Jun 19th, 2007, 06:14 PM   #1
blakemckenna
PowerPoster
 
Join Date: Jan 04
Posts: 2,531
blakemckenna is an unknown quantity at this point (<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, 06:26 PM   #2
techgnome
Invisible
 
Join Date: May 02
Posts: 13,263
techgnome has much to be proud of (1500+)techgnome has much to be proud of (1500+)techgnome has much to be proud of (1500+)techgnome has much to be proud of (1500+)techgnome has much to be proud of (1500+)techgnome has much to be proud of (1500+)techgnome has much to be proud of (1500+)techgnome has much to be proud of (1500+)techgnome has much to be proud of (1500+)techgnome has much to be proud of (1500+)techgnome has much to be proud of (1500+)
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
__________________
How to Use Parameters
* 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.*
* Got Eels in your Hovercraft? *
* Your guide to The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
*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, 07:01 PM   #3
blakemckenna
PowerPoster
 
Join Date: Jan 04
Posts: 2,531
blakemckenna is an unknown quantity at this point (<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, 08:30 PM   #4
jmcilhinney
.NUT
 
jmcilhinney's Avatar
 
Join Date: May 05
Location: Sydney, Australia
Posts: 54,913
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, 2008, 2009, 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 | C# (ForumAccount has translated some of my VB submissions to C#)
My Blog: Defining and Raising Custom Events | Manipulating GDI+ Drawings | Using Parameters in ADO.NET
jmcilhinney is offline   Reply With Quote
Old Jun 19th, 2007, 08: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 08:36 PM.
Bulldog is offline   Reply With Quote
Old Jun 20th, 2007, 10:08 AM   #6
blakemckenna
PowerPoster
 
Join Date: Jan 04
Posts: 2,531
blakemckenna is an unknown quantity at this point (<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 Search this Thread
Search this Thread:

Advanced Search
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 02:01 PM.




To view more projects, click here

Acceptable Use Policy


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.