|
Hi,
in the OnPaint method of the Control/Form you want to draw your shapes in, have a for loop
that generates random x,y,width,height values (all within legal bounds), and call
Graphics.DrawRectangle (or FillRectangle) for each of them.
Alternatively, generate those numbers elsewhere and store them; then have your OnPaint feed
them to Graphics.DrawRectangle.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
How would I select a large amount of (say) rect1 - 25? I saw a post a while back that did something close, but I can't find it. It's like...
(my example)
rect(and a for loop here)<br />
{<br />
<br />
}
... or something like it
-- modified at 11:28 Saturday 1st December, 2007
- I love D-flat!
|
|
|
|
|
Something along these lines:
List< Rectangle> rects=new List< Rectangle>;
Random rand=new Random();
for (int i=0; i< RECT_COUNT; i++) {
int x=rand.Next(xBounds);
int y=rand.Next(yBounds);
int w=rand.Next(widBounds);
int h=rand.Next(heiBounds);
Rect r=new Rectangle(x,y,w,h);
rects.Add(r);
}
...
Graphics g=e.Graphics;
foreach(Rectangle r in rects) {
g.DrawRectangle(r);
}
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Oh. Thanks.
- I love D-flat!
|
|
|
|
|
I want to clip the cursor into any closed figure that have been drawn using graphicspath and have been transformed aswell. I want this to be done in GDI of C#. The default clip property of cursor is limited to clip it under rectangular area.
Sharjeel H Khan
|
|
|
|
|
I have declared an array like this
"ArrayList tableNames = new ArrayList();"
and I have added some values to it using
"tableNames.Add(row["TABLE_NAME"].ToString());"
Now I want to traverse it untill the last element.
Reply Hurry!
Regards,
chanzeb chaudhary
|
|
|
|
|
StringBuilder mybuilder=new StringBuilder();
foreach(string s in tableNames)
{
mybuilder.Append(s)
}
|
|
|
|
|
chanzeb wrote:
Reply Hurry!
That is rather rude.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
|
|
|
|
|
chanzeb wrote: Reply Hurry
You must be joking.
Your question tells me that you're very new to C#. You should buy a beginner book and work through it. You should certainly be aware of basic language constructs like for each before you start trying to work with databases, etc.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
First, learn about foreach .
Second, learn about System.Collections.Generic.List<string> .
Third, learn that the .ToString() on your row["TABLE_NAME"] is likely unnecessary, try a cast instead.
Fourth, if you're already traversing a DataTable why are you even asking?
|
|
|
|
|
what will i do to have an inputed value in a textbox in form 1 and and have that value appears on another textbox in form2?
thanks!!
|
|
|
|
|
|
hello can sombady help me with this problem.
i want open and close a form with wan button.
|
|
|
|
|
Open and close the SAME form with one button, or two different forms?
Have you tried this yourself yet? Did you come to a problem, and if so, what was it?
My current favourite word is: PIE!
I have changed my name to my regular internet alias. But don't let the 'Genius' part fool you, you don't know what 'SK' stands for.
-The Undefeated
|
|
|
|
|
Please rephrase question because it is not very clear what you are wanting to do.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
|
|
|
|
|
hi
I have an event defined in a base class. I'd like to raise this directly from a derived class, but the compiler won't let me do this, so instead I created a method RaiseMyEvent(...) to raise the event in the base class. Can I raise the event a simpler way? (otherwise I'd need to create a RaiseEventX function for each event..)
thanks!
|
|
|
|
|
No you can't.
There is a really good article on events here
[^].
|
|
|
|
|
when we create application form in visual c# in solution tab there is some think name refrence what is this plz any tell me in detail
wasim khan
|
|
|
|
|
If you define a reference to another assembly in a project, you can call code in that assembly from the project.
BTW, this is a pretty basic question. You should really read a beginner's book on C#.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
pmarfleet wrote: You should really read a beginner's book on C#.
I believe so.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
|
|
|
|
|
Hi...I am trying to detect connection of a device with system using com port...i want to show a message box when a device is plugged in and plugged out.....How can i do it?
Vishal
|
|
|
|
|
Hi,
there basically are two approaches, both requiring some cooperation from the device:
1.
by hardware signaling:
if your device is pulling one of the control pins, you can detect that by looking at
some SerialPort properties (CtsHolding, CdHolding, ...) or wiring its PinChanged event.
Of course that would not tell you for sure which device is attached.
2.
by software polling:
the device might periodically send some data, which you could read (possibly thru the
DataReceived event); or you could periodically ask it to send something (timer+Write+Read).
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Thanks a lot buddy....i am sure now that i can implement it..
|
|
|
|
|
I am developing an application in which i need to increase decrease size of form on timer tick.
Means for a the height of the form will increase upto defined size and after getting to that certain point of height the size of the form will start decreasing to the defined point.
|
|
|
|
|
Well, you can change the form size using the Width and Height properties. Then you can just increase those until you get to the size you want, then start decreasing them, here let me give you an example:
int Difference = 5;
int MaxWidth, MinWidth, MaxHeight, MinHeight;
timerTick()
{
this.Width += Difference;
if(this.Width >= MaxWidth) {
this.Width = MaxWidth;
Difference *= -1;
} else if(this.Width <= MinWidth) {
this.Width = MinWidth
Difference *= -1;
}
}
My current favourite word is: PIE!
I have changed my name to my regular internet alias. But don't let the 'Genius' part fool you, you don't know what 'SK' stands for.
-The Undefeated
|
|
|
|