|
Is it possible to get "handel" and "bedrijf" into a combobox?
And when i add an new school in the xml-file, i want that name also in the combobox
Thanks in advance!
<?xml version="1.0" standalone="yes"?>
<test nr="1">
<school naam="handel">
<direc> guy</direc>
<teur> qui</teur>
</school>
<school naam="bedrijf">
<direc> louis</direc>
<teur> qyu</teur>
</school>
</test>
|
|
|
|
|
The DataSet treats attributes as either tables or fields, depending on where you are. For example, this schema would also produce a table called "1". The "naam" will be just another field in your "school" table, so you can use it just like any other field.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi gurus,
in MFC and GDI+ I could easily randomize brushes, colors, GDI+ enumerations and so on... My question is simple.
How can I do the same things in C#?
I would like to randomize the following C# elements:
- Color (RGB values. Alhpa remains the same)
- Brushes (LinearGradientBrush, SolidBrush and HatchBrush)
- Brushes styles (LinearGradientMode and HatchStyle)
For example, in C++ I could do the following:
<br />
m_pRandom->SetBounds(HatchStyleHorizontal, HatchStyleTotal);<br />
m_hs=(HatchStyle) m_pRandom->GetRandom();<br />
while m_hs is HatchStyle and m_pRandom is a random object.
I could easily randomize in C++ between different enumerations. How can I do the same in C#?
Thanks for the help.
Best regrads.
|
|
|
|
|
At least one way of handling this would be to create an ArrayList, which would hold the objects you want to access randomly. Then, your random number could simply index the array, returning the object you want.
John
"You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.
|
|
|
|
|
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
|
|
|
|
|
I understand now that everything happens in the Next method.
but when I want to assign a new radomize value to a Color object, the compiler says that A, R, G and B are read-only properties
|
|
|
|
|
Oops, that's right. Do the same thing only use the Color.FromArgb(int, int, int) method.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
yeap, it works that way
Thanks.
For, the brushes, is it possible to create only 1 brush instead of an array that contains all brushes? I want to create the brush at run time to do something similar to the following C++ code:
<br />
void CBlock::InitializeBrush()<br />
{<br />
SAFE_DELETE(m_pBrush);<br />
<br />
switch (m_bt)<br />
{<br />
case BrushTypeSolidColor:<br />
m_pBrush=new SolidBrush(m_clrForeground);<br />
break;<br />
<br />
case BrushTypeLinearGradient:<br />
m_pBrush=new LinearGradientBrush(m_rect, m_clrForeground, m_clrBackground, m_lgm);<br />
break;<br />
<br />
case BrushTypeHatchFill:<br />
m_pBrush=new HatchBrush(m_hs, m_clrForeground, m_clrBackground);<br />
break;<br />
}<br />
}<br />
while m_bt is a BrushType, m_lgm is a LinearGradientMode.
I guess I have to create an array with all the "BrushType" in a similar way to
what you show me with the LinearGradientMode?
|
|
|
|
|
You mean something using the same concepts like the following?
public Brush GetRandom()
{
Random rand = new Random();
switch (rand.Next(3))
{
case 1: return new LinearGradientBrush(Bounds, ForeColor, BackColor,
LinearGradientMode.Horizontal);
case 2: return new HatchBrush(HatchStyle.Wave, ForeColor);
default: return new SolidBrush(ForeColor);
}
}
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
ok, it works that way
Thanks a lot!
One more thing about randoms in C#.
How can I get a new value each time I instanciate a Random class?
It seems that when I trace the values, in my array, I have identical series of values. I guess it's like for C++, these series correspond to one second. How can I generate a completely different value each time I instanciate a Random class? Is there somewhere a kind of GetTickCount in C#?
|
|
|
|
|
oops,
I posted the message as anonymous... that message was mine
|
|
|
|
|
I reply to this one, then, to make sure you get a notification email (if configured in your settings for CP).
Yes, just use DateTime.Millisecond or some other int or long like Environment.TickCount .
If you always use the same seed, you'll always get the same sequence of "random" numbers, but it isn't - nor can it be without peripherals based on chaos principals or something similar - truly random.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hum, that's strange,
When I use DateTime.Today.Milliseconds in the constructor of Random, I have always the same values, and when I use Environment.TickCount, I have series that have the same value and it seems it correspond to a second.
In C++ I could get using the new operator a really different instance and initialization of the random generator, then each time a constructor's object of the array had a different set of values.
the thing is that I have an array of Block, and each Block's constrcutor instanciate a Random class in its constructor. but I have series of values for the moment
How can I get completely different values each time I have a new Block in my array of blocks? The goal is to get an array of block that are completely different.
Thanks for to help me to learn C#
|
|
|
|
|
All I can tell you is that seeding the Random class with a different seed will create a different series of random numbers. Depending on how fast these objects are being created, it's possible the resolution of the seed you're using isn't great enough to be different. Debug your app (which will slow it down) and make sure that you're getting different values form DateTime.Now.Millisecond for each constructor, or from Environment.TickCount .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi everyone. This is my first post
Firstly I would like to say that this seems like a very valuable site for the inexperienced like myself. I am literally in my first week of development and comprehension of C#. So I think a few newbie questions must be expected.
My problem is this. I have never used the commandline. For the project I am working on now, I must make an assembly. But the only way that the .NET documentation says you can do this is through the commandline. This is terrible Could someone please help me in just pointing out where I can do this in the IDE
Thanks
Skylo
|
|
|
|
|
Skylo wrote:
But the only way that the .NET documentation says you can do this is through the commandline.
If you've got your solution in the IDE already then to compile it all you need to do is select Build-->Build Solution or press Ctrl+Shift+B
To run the assembly (assuming it is an exe) you can press F5 or use the menu Debug-->Start.
Does this help?
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
|
|
|
|
|
Hi Colin. Thank you very much for the reply. I know about de-bugging and what not but what I would like to do is create an assembly. I have three projects in a solution.
Now I understand that an assembly is almost like a casing that one may put a class in, in order that one may use the class throughout the other projects. This is what I am confused about: ms-help://MS.VSCC.2003/MS.MSDNQTR.2004JAN.1033/cpguide/html/cpconbuildingsingle-fileassembly.htm.
That seems like the only documentation I can find on assemblies?
I hope that helps you understand my dilemma
|
|
|
|
|
Hi,
You're link didn't work for me - I must have a different version of MSDN installed. Can you tell me the title of the document so I can look it up - or provide the equivalent link to the online version of MSDN? Thanks.
If you can debug your solution then you already have the assemblies. An assembly is just a .NET DLL or EXE file. When you Build your solution the assemblies are places in the bin/Debug or bin/Release directories within your individual project directories.
To use assemblies in different projects within a solution you must add a reference to the assembly you want to use in the project that you want to access it. To do this right click the References node in the solution explorer and select "Add Reference". Click the "Projects" tab and select the project that contains generates the assembly you want to use. In individual .cs files you should add a using statement at the top with the namespace of the code in the assembly you are using.
Some good practice is that an assembly should only contain one namespace, or one branch of a namespace structure.
I'm kind of hitting out in the dark here. Let me know if anything seems to be going in the right direction.
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
|
|
|
|
|
Thanks Colin. All is good. Your explanation has helped me. The title that I was refering to was "Building Assemblies". Confusing this Microsoft thing. In Java everything is laid at our feet!
...one of the main causes of the fall of the Roman Empire was that,
lacking zero,
they had no way to indicate successful termination of their C programs.
-Robert Firth-
|
|
|
|
|
The .NET Framework SDK itself is not tied to Visual Studio .NET (VS.NET). VS.NET is merely a helpful IDE that helps with development tasks, but everything it does when building assemblies you can do from the command-line, such as using the C# command-line compiler (csc.exe), the license generator (licgen.exe) and the resource generator (resgen.exe). Utilities that are similar in use to when VS.NET creates Web Service proxies or COM interop assemblies are wsdl.exe and soapsuds.exe, and for interop tlbimp.exe and aximp.exe. If you were to register your CCW (COM-Callable Wrapper, a .NET class exposed as a COM class) you can use regasm.exe and optionally tlbexp.exe to generate a typelib for your classes in that assembly.
"Building Assemblies" merely discusses this from the SDK standpoint, which comes with all these programs (actually, some come with the Framework itself like the command-line compilers). Anyone can download the SDK and build without VS.NET. I find myself doing it a lot when I need a quick test or example code to use here on this forum.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Wow. Thank you very much Heath. You guys have been very helpful. I think I have found a "home". Now doing a conversion of a .csv to a .xml then through to a datagrid.
Will be asking a few questions, I am sure of that.
Keep well and happy programming to all
Skylo
...one of the main causes of the fall of the Roman Empire was that,
lacking zero,
they had no way to indicate successful termination of their C programs.
-Robert Firth-
|
|
|
|
|
Skylo wrote:
Will be asking a few questions, I am sure of that.
No problem, but let give my usual drivel about checking the docs first. It's obvious from your previous post that you did read through a particular topic already, so - congrats - you're on your way (much more than many people, believe me). Self-discovery always teaches you more than being told.
See the System.Xml namespace for help. Creating XML documents (and reading and modifying them, of course) is very easy with .NET.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I've tried to set the background on my component to transparent, but i get an error saying that the component does not support transparent backgrounds. Is there a way around this?
Cata
|
|
|
|
|
Transparency is not controlled at the control level, but rather at the form level. You can see this easily if you create a sample project WindowsForm project, add some conrtrols, and view the properties of the controls, then the form. So unless you are doing a DropDown control in PropertyGrid, you would handle your transparency at the form level. If you are doing PropertyGrid dropdowns, you cannot be transparent since IServiceProvider is only fed a control instead of a form.
To handle transparency, your code would be something like:
System.Windows.Forms.Form newForm = new Form();
MyNamespace.MyControl digit = new MyControl();
newForm.Controls.Add(digit);
newForm.Opacity = 60;
newForm.Show();
_____________________________________________
Of all the senses I could possibly lose, It is the one called 'common' that gets lost the most.
|
|
|
|
|
Hi,
Thanks for the reply, but that's not what i'm looking for. When i try and use a color containing alpha channels as any type of background color on a component, it throws an exception.
i.e.
this.BackColor = Color.FromArgb(0,this.BackColor);
This is a custom component, not one that is pre built into .net, and i know that these ones do support alpha channels, so i'm a bit confused as to how to implement it in mine.
Cheers
Cata
|
|
|
|
|