starcraft Posted July 1, 2003 Posted July 1, 2003 i have lots of this probubly 40 or more, is there an easier way to code this? f6space.Show() With f6space .ForeColor = Color.Green .BackColor = Color.Black End With f7space.Show() With f7space .ForeColor = Color.Green .BackColor = Color.Black End With f8space.Show() With f8space .ForeColor = Color.Green .BackColor = Color.Black End With g1space.Show() With g1space .ForeColor = Color.Green .BackColor = Color.Black End With ps its vb not c sorry Quote
*Experts* mutant Posted July 1, 2003 *Experts* Posted July 1, 2003 What are the fxspace objects? Quote
*Experts* mutant Posted July 1, 2003 *Experts* Posted July 1, 2003 You could do this: Dim lbl As Label For Each lbl In Me.Controls lbl.ForeColor = Color.Green lbl.BackColor = Color.Black Next This will change all your labels on your form. Quote
starcraft Posted July 1, 2003 Author Posted July 1, 2003 (edited) o cool thanks, i probubly should have said this before but is there a way to alternate the back colors without doing to manually? i'm making a checkerboard affect. Sorry that worked wonderfully by the way thanks again wait while i have your attention i got a question. Is Dim like telling it to 'set'? Edited July 1, 2003 by starcraft Quote
starcraft Posted July 2, 2003 Author Posted July 2, 2003 this is only to let ppl now that there is a 2nd question Quote
*Experts* mutant Posted July 2, 2003 *Experts* Posted July 2, 2003 You have alternate it manually. Set is no longer supported in .NET, Dim just initializes a variable so you can use it later. Quote
*Experts* mutant Posted July 2, 2003 *Experts* Posted July 2, 2003 Or you can do something like this to draw a checker board (im saying something like this becuase I dont know the size of checker board but i know the size of a chess board :) ) (this is assuming the size of each square is 45) Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load SetStyle(ControlStyles.DoubleBuffer, True) 'to reduce flicker if there will be any End Sub Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint For x As Integer = 0 To 360 Step 90 For y As Integer = 0 To 360 Step 90 e.Graphics.FillRectangle(New SolidBrush(Color.Black), x, y, 45, 45) Next Next For x As Integer = 45 To 315 Step 90 For y As Integer = 0 To 360 Step 90 e.Graphics.FillRectangle(New SolidBrush(Color.White), x, y, 45, 45) Next Next For x As Integer = 45 To 315 Step 90 For y As Integer = 45 To 315 Step 90 e.Graphics.FillRectangle(New SolidBrush(Color.Black), x, y, 45, 45) Next Next For x As Integer = 0 To 360 Step 90 For y As Integer = 45 To 315 Step 90 e.Graphics.FillRectangle(New SolidBrush(Color.White), x, y, 45, 45) Next Next End Sub Each of the loops draws rows of squeres that alternate. Quote
*Experts* Volte Posted July 2, 2003 *Experts* Posted July 2, 2003 You could eliminate two of those loops by simply filling the whole form with white and then drawing black squares with the loop. It might not affect performance, I don't know, but since it's happening every time the form is drawn, it might. Quote
*Experts* mutant Posted July 2, 2003 *Experts* Posted July 2, 2003 Each of those loops is drawing only 4 times. If you set the background to white or black they board will get confusing becuse you will be able to see only one color coming out as some kind of a shape and the rest will not seem like part of the board :) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.