Click here to Skip to main content
15,912,977 members
Home / Discussions / C#
   

C#

 
GeneralRe: Picture Flickering(Lagg) Pin
Snowjim30-Mar-04 5:59
Snowjim30-Mar-04 5:59 
GeneralRe: Picture Flickering(Lagg) Pin
Stefan Troschuetz30-Mar-04 4:39
Stefan Troschuetz30-Mar-04 4:39 
GeneralRe: Picture Flickering(Lagg) Pin
Snowjim30-Mar-04 6:02
Snowjim30-Mar-04 6:02 
GeneralXml attributes in a combobox Pin
bertcox30-Mar-04 2:52
bertcox30-Mar-04 2:52 
GeneralRe: Xml attributes in a combobox Pin
Heath Stewart30-Mar-04 4:49
protectorHeath Stewart30-Mar-04 4:49 
GeneralRandom in C# Pin
bouli30-Mar-04 2:43
bouli30-Mar-04 2:43 
GeneralRe: Random in C# Pin
John Fisher30-Mar-04 4:07
John Fisher30-Mar-04 4:07 
GeneralRe: Random in C# Pin
Heath Stewart30-Mar-04 4:10
protectorHeath Stewart30-Mar-04 4:10 
If you mean you just want to pick random colors, hatches, or brushes, then just pack them into an array or list and select a random number over that range. For colors, you could do something like this:
Random rand = new Random();
Color c = new Color();
c.R = rand.Next(256);
c.G = rand.Next(256);
c.B = rand.Next(256);
If you're getting a pixel from somewhere else, just don't touch the A property (the alpha channel). Note that since Color is a value type, you cannot change these propeties on a Color that is referenced by another class or struct. You'd have to copy it or create a new one then reassign that color property.

For selecting anything else, just put them in a an array and select a random index like so:
Brush[] brushes = new Brush[] {
  new LinearGradientBrush(...),
  new HatchBrush(...),
  ...};
Random rand = new Random();
Brush brush = brushes[rand.Next(brushes.Length)];
You could do the same with hatch styles, although you can make this easier by using the Enum class:
HatchStyle[] styles = (HatchStyle[])Enum.GetValues(typeof(HatchStyle));
Random rand = new Random();
HatchStyle style = styles[rand.Next(styles.Length)];


 

Microsoft MVP, Visual C#
My Articles
GeneralRe: Random in C# Pin
bouli30-Mar-04 4:21
bouli30-Mar-04 4:21 
GeneralRe: Random in C# Pin
Heath Stewart30-Mar-04 4:26
protectorHeath Stewart30-Mar-04 4:26 
GeneralRe: Random in C# Pin
bouli30-Mar-04 4:32
bouli30-Mar-04 4:32 
GeneralRe: Random in C# Pin
Heath Stewart30-Mar-04 4:41
protectorHeath Stewart30-Mar-04 4:41 
GeneralRe: Random in C# Pin
Anonymous30-Mar-04 5:54
Anonymous30-Mar-04 5:54 
GeneralRe: Random in C# Pin
bouli30-Mar-04 5:58
bouli30-Mar-04 5:58 
GeneralRe: Random in C# Pin
Heath Stewart30-Mar-04 6:20
protectorHeath Stewart30-Mar-04 6:20 
GeneralRe: Random in C# Pin
bouli30-Mar-04 6:27
bouli30-Mar-04 6:27 
GeneralRe: Random in C# Pin
Heath Stewart30-Mar-04 8:30
protectorHeath Stewart30-Mar-04 8:30 
GeneralAssemblies Pin
Skylo30-Mar-04 0:22
Skylo30-Mar-04 0:22 
GeneralRe: Assemblies Pin
Colin Angus Mackay30-Mar-04 0:40
Colin Angus Mackay30-Mar-04 0:40 
GeneralRe: Assemblies Pin
Skylo30-Mar-04 0:48
Skylo30-Mar-04 0:48 
GeneralRe: Assemblies Pin
Colin Angus Mackay30-Mar-04 1:05
Colin Angus Mackay30-Mar-04 1:05 
GeneralRe: Assemblies Pin
Skylo30-Mar-04 1:30
Skylo30-Mar-04 1:30 
GeneralRe: Assemblies Pin
Heath Stewart30-Mar-04 4:00
protectorHeath Stewart30-Mar-04 4:00 
GeneralRe: Assemblies Pin
Skylo30-Mar-04 4:22
Skylo30-Mar-04 4:22 
GeneralRe: Assemblies Pin
Heath Stewart30-Mar-04 4:29
protectorHeath Stewart30-Mar-04 4:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.