|
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
|
|
|
|
|
Hi!
I need help, my problem is that i need to know when the scrollbar in a RichTextBox reaches the bottom. I know that vScrollbar and hScrollbar has a value that you can set or get but how to do this in a RichTextBox?
Thanks!
Johan
|
|
|
|
|
You can either P/Invoke SendMessage and use the SBM_ messages to sent to the handle for the RTF control (see RichTextBox.Handle , inheritted from Control ), or P/Invoke the recommended scroll functions like GetScrollPos :
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.SysInt)]
private static extern int GetScrollPos(IntPtr hWnd,
[MarshalAs(UnmanagedType.SysInt)] int nBar);
private const int SB_HORZ = 0;
private const int SB_VERT = 1;
private const int SB_CTL = 2; To note, GetScrollPos is provided for backwards compatibility for older code and the Platform SDK docs recommend that you use GetScrollInfo instead, which also requires that you declare a struct for use with the P/Invoke method.
Using the method above, you can get the scroll position for the range (the page in this case) using something like this:
int pos = GetScrollPos(myRTFControl.Handle, SB_VERT); If you need to know what the range is, you can use the GetScrollRange . In this case, though, you could actually get both the position and range back at the same time if you did use GetScrollInfo . This is enough information to get you going, though.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks for the answer!
I will try it!
/Johan
|
|
|
|
|
I cant get it to work...
mabye i do it wrong??
I have tryied the GetScrollPos as in the code above but i get a error when i run the program that is:
marshal return value: Invalid managed/unmanaged type combination (Int32/Uint32 must be paried with I4 or U4)
And i dont know how to work this one out...
Please help...
Thanks
Johan
|
|
|
|
|
Oops, typo! Change UnmanagedType.SysInt to UnmanagedType.U4 as the exception message suggests.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have a Xml document like this and i want to show the databases of session "Development" in a datagrid. But i don't know how.
If i do it like this:
ds.ReadXml(@"c:\xmlfile.xml");
dataGrid1.DataSource = ds;
dataGrid1.DataMember = "database";
He will take the databases of both sessions, i just want the databases of the first OR the second session.
Thx in advance.
<?xml version="1.0" standalone="yes"?>
<sessions version="1.0">
<session name="Development">
<databases>
<database name="ffw100">
<physicalname>fastforward</physicalname>
<databaseorder>1</databaseorder>
</database>
</databases>
</session>
<session name="AppserverDevelopment">
<databases>
<database name="ffw100">
<physicalname>fastforward\ffw100</physicalname>
<databaseorder>1</databaseorder>
</database>
</databases>
</session>
</sessions>
|
|
|
|
|
That's not a valid format for a DataSet , so you won't be able to bind to the elements you want. DataSet s have either 2 or 3 levels. In the case of 1 level below the root (which is required by XML) a generic table name is used, IIRC, like "Table1", but you can always just use dataSet1.Tables[0] . In the case of 2 levels below the root each parent element is the table name and each child (leaf) element is a field. Each instance of the parent elements counts as a row, like so:
<DataSet>
<Table1>
<ID />
<Name />
</Table1>
<Table1>
<ID />
<Name />
</Table1>
<Table2>
<Stuff />
</Table2>
</DataSet> So this DataSet would have to two tables named "Table1" and "Table2". Table1 would have two rows and Table2 would have one. There's really not any other ways you can represent such a simple structure.
My suggestion is to extract the <databases< element(s) and put those into a separate DataSet (see the XmlDataDocument for some help with that) and bind against that.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
As Heath mentioned, your XML file is too complex for the dataset to properly parse. However, once you do have a dataset representation, binding to a specific session can be done by using a DataView of the table and setting the Row filter.
For example, I modified your source XML as follows, so that it can be parsed by the dataset.
<br />
<?xml version="1.0" standalone="yes"?><br />
<databases><br />
<br />
<!-- Development Sessions --><br />
<br />
<database><br />
<name>ffw100"</name><br />
<session>Development</session><br />
<physicalname>fastforward</physicalname><br />
<databaseorder>1</databaseorder><br />
</database><br />
<br />
<!-- AppDevelopment Sessions --><br />
<br />
<database><br />
<name>ffw100</name><br />
<session>AppDevelopment</session><br />
<physicalname>fastforward\ffw100</physicalname><br />
<databaseorder>1</databaseorder><br />
</database> <br />
</databases> <br />
Once you have the dataset, you can use a dataview to filter it before biding to the grid. The following code will bind the grid to only those databases used in the "Development" session. It will also sort by the "DatabaseOrder" node.
<br />
DataSet ds = new DataSet();<br />
ds.ReadXml(@"c:\test.xml");<br />
<br />
DataView dv = ds.Tables[0].DefaultView;<br />
dv.RowFilter = "SESSION='Development'";<br />
dv.Sort = "DATABASEORDER ASC";<br />
<br />
dataGrid1.DataSource = dv;<br />
dataGrid1.DataMember = "NAME";<br />
dataGrid1.DataBind();<br />
Hope that helps.
--Jesse
|
|
|
|