|
Hmmm...don't know of any way to do what you want using ChangeType . I assume you're using the Convert.ChangeType Method (Object, Type, IFormatProvider) overload of the method? Have you tried passing in a NumberFormatInfo object as the IFormatProvider ?
|
|
|
|
|
Yes, I tried that. It does not work with numbers surrounded with parenthesis and that class does not take a NumbersStyles argument or property.
-----
If atheism is a religion, then not collecting stamps is a hobby. -- Unknown
God is the only being who, to rule, does not need to exist. -- Charles Baudelaire
|
|
|
|
|
Those are the only things I know that might work. You may end up needing to create your own version of a ChangeType class that knows how to handle your special cases.
|
|
|
|
|
I think you can do this with TypeConverter s, but I am not sure...
[ My Blog] "Visual studio desperately needs some performance improvements. It is sometimes almost as slow as eclipse." - Rüdiger Klaehn "Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe
|
|
|
|
|
Hi!
I want to create a list box and its items should include a text and a picture (icon).
Has anybody an idea how to realize that?
regards
Gernot
|
|
|
|
|
You would need to subclass the ListBox and provide your own drawing routines. Have you looked[^] here on CP?
|
|
|
|
|
hi
here is my code
first My Listbox1 has a name panellist
second make sure to set PanelList.DrawMode = DrawMode.OwnerDrawVariable;
third fill the list with with 5 items
NOTE : this code is not full example it's just and right idea
private void PanelList_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)<br />
{<br />
SolidBrush br = new SolidBrush(Color.Navy );<br />
Image img = PicFavorites.Image;<br />
StringFormat sf = new StringFormat();<br />
sf.Alignment = StringAlignment.Far ;<br />
sf.LineAlignment = StringAlignment.Center ;<br />
e.DrawBackground();<br />
br.Color = Color.Navy ;<br />
e.Graphics.DrawString(PanelList.Items [e.Index].ToString () ,e.Font ,br,e.Bounds ,sf );<br />
switch (e.Index )<br />
{<br />
case 1:<br />
{<br />
img = PicGeneral.Image;<br />
}<br />
break;<br />
case 2:<br />
{<br />
img = PicEditView.Image;<br />
}<br />
break;<br />
case 3:<br />
{<br />
img = PicIncomingCalls.Image;<br />
}<br />
break;<br />
case 4:<br />
{<br />
img = PicServices.Image;<br />
}<br />
break;<br />
case 5:<br />
{<br />
img = PicSetting.Image;<br />
}<br />
break;<br />
default:<br />
break;<br />
}<br />
e.Graphics.DrawImage (img ,e.Bounds.X + 10, e.Bounds.Y );<br />
e.DrawFocusRectangle();<br />
<br />
}<br />
<br />
private void PanelList_MeasureItem(object sender, System.Windows.Forms.MeasureItemEventArgs e)<br />
{<br />
e.ItemHeight = 48;<br />
}
I know nothing , I know nothing
|
|
|
|
|
Does anyone know how to set the readonly attribute of an class property at runtime.
Code example:
Class Myclass
{
private int x=0;
private int y=0;
[readonly(true),Description("Set X value")]
public int X
{
get{return x;}
set{x=value;}
}
[readonly(false),Description("Set Y value")]
public int Y
{
get{return y;}
set{y=value;}
}
}
|
|
|
|
|
By definition you cant. The nature of Attributes means that they rely on being just metadata.
I think you are also confusing the meaning of the ReadOnly attribute - it is used to tell the IDE that the property should not appear in the Properties Grid.
|
|
|
|
|
Confusing with the meaning!!! Well, not really...
by doing some searching on the site. i found what i was looking for.
http://www.codeproject.com/useritems/dynamicattributes.asp[^]
But you are right, "by definition" its only an metadata.
What i needed was, an simple function for the propertyGrid to enable and disable an field...
So all in all, its manageable...:-> :-> :->
|
|
|
|
|
PawJershauge wrote: What i needed was, an simple function for the propertyGrid to enable and disable an field...
PawJershauge wrote: Confusing with the meaning!!! Well, not really...
Yes really, your original post makes no mention of the PropertyGrid. The code I posted works and directly answered the question from your original post.
This is CodeProject.com not Prognostication.com.
|
|
|
|
|
well im not going to argue with you, but i did write the attributes in my class, and thats what i wanted to change...
case closed...
|
|
|
|
|
PawJershauge wrote: Does anyone know how to set the readonly attribute of an class property at runtime.
Is this a trick question?
public class Myclass
{
private int x = 0;
private int y = 0;
[ReadOnly(true), Description("Set X value")]
public int X
{
get { return x; }
set { x = value; }
}
[ReadOnly(false), Description("Set Y value")]
public int Y
{
get { return y; }
set { y = value; }
}
}
Myclass mc = new Myclass();
mc.X = 10;
Debug.WriteLine(String.Format("Myclass.X: {0}", mc.X));
|
|
|
|
|
No its not.
Please look at my reply above...
|
|
|
|
|
I'm remaking a game I made in C#, it was originally in C++ using Borland BGI Graphics. I made an array of picture boxes but the picture boxes won't show up (using Visual Studio 2005 Pro):
Code:
<br />
<br />
const Byte MAX_ROWS = 20;<br />
const Byte MAX_COLS = 20;<br />
PictureBox[,] PicBoxes = new System.Windows.Forms.PictureBox[MAX_ROWS, MAX_COLS];<br />
<br />
private void draw_image(Byte type, int row, int col)<br />
{<br />
PicBoxes[0, 0].Name = "pictureBox1";<br />
PicBoxes[0, 0].Image = Bulldozer_2._0.Properties.Resources.bulldozer_down;<br />
PicBoxes[0, 0].Size = new System.Drawing.Size(32, 32);<br />
PicBoxes[0, 0].Visible = true;<br />
PicBoxes[0, 0].Enabled = true;<br />
PicBoxes[0, 0].IsAccessible = true;<br />
PicBoxes[0, 0].Show();<br />
PicBoxes[0, 0].Location = new System.Drawing.Point(5, 5);<br />
}<br />
When I put a breakpoint on the first line in the "draw_image" function the PicBoxes array shows up as locked. How do I unlock it?
-- modified at 21:15 Tuesday 28th August, 2007
|
|
|
|
|
Jordanwb wrote: the picture boxes won't show up
Where would they show up? You haven't added them to a form.
Jordanwb wrote: the PicBoxes array shows up as locked
What do you mean by that? Where does it show up? In what way is it "locked"?
---
single minded; short sighted; long gone;
|
|
|
|
|
|
Jordanwb wrote: Well the first part you'd find out by looking at the code.
What do you mean by that?
I explained why the controls doesn't show up. Is it something about it that you don't understand?
Jordanwb wrote: The second part is hard to explain.
Well, could you try? I can't really help you if I have no idea what you are talking about...
Jordanwb wrote: The Image property is set a few lines up but it's still set to null.
Then obviously you set it to null. What does Picture_Refs contain?
The code that is visible in the picture is quite different from the code in your original post. What does the code look like really?
---
single minded; short sighted; long gone;
|
|
|
|
|
I gave a link in my previous post where you can download the project and see for yourself.
|
|
|
|
|
Jordanwb wrote: I gave a link in my previous post where you can download the project and see for yourself.
See what? I have no idea what you are talking about. There is no such thing as a "locked" array, so you have to explain what you mean by that. I could try out your project, but if I don't know what to look for, how do you expect me to see it?
---
single minded; short sighted; long gone;
|
|
|
|
|
Hi
I am new to cSharp and i would like to know how to generate a random number?? what code would i need to use??
I am aware of a method 'public virtual int Next();' However is there a easier way round this?
Any help is much appreciated.
Cheers
|
|
|
|
|
...you seem to be new to more than just C# ..a simple search of "C# random" on the MSDN returns this at the top of their results..quite ironic I might add. I went to the MSDN to answer your question and Microsoft sent me back here lol. The solution provided in that article is probably overkill to your original question, but it is a great source for learning about random number generation
"I need build Skynet. Plz send code"
|
|
|
|
|
Random rnd = new Random();
rnd.Next();
easier than what? :P
Two lines is neither Hard nor Complex.
I suppose you could make your own method that would allow you to turn your 2 lines into 1, but I don't think it'll save you much devlopment time!
Random needs a seed and so needs to be constructed as you might want the same seed as a previous time or a new seed.
You then need to get each random number so a method call is needed, which also has multiple overloads so you can specifiy the number range if you wish.
If you want to remove all the flexability provided by the different parameters you can pass to the constructor and method then go ahead but as I said is it really worth it to save a single line of code?
Thats assuming you only use it once of course! the more times you use rnd.Next() without creating a new instance of rnd the difference in total lines gets less and less.
|
|
|
|
|
Random rnd = new Random(); rnd.Next();
one line
|
|
|
|
|
F16I wrote: Random rnd = new Random(); rnd.Next();
one line
int r = new Random().Next();
really one line
---
single minded; short sighted; long gone;
|
|
|
|