|
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;
|
|
|
|
|
Extending off of originSH's post, you generally don't want to reseed the generator each time. THe seed is taken from the system clock and as a result if you do multiple calls back to back within a few dozen milliseconds while reseeding before each number generated you'll get the same return for all of them.
--
You have to explain to them [VB coders] what you mean by "typed". their first response is likely to be something like, "Of course my code is typed. Do you think i magically project it onto the screen with the power of my mind?" --- John Simmons / outlaw programmer
|
|
|
|
|
Is there a way to set the ForeColor for only the displayed text in a ComboBox control? In other words, can I set the text of the selected item to, say, Color.Red, while keeping the other items in the list as Color.Black (or any other color I desire)?
Thanks.
|
|
|
|
|
Hello,
Basically you could inherit your own ComboBox from System.Windows.Forms.ComboBox:
public class SpecialComboBox : System.Windows.Forms.ComboBox
{
In the classes constructor you have to change the "DrawMode" property:
public SpecialComboBox()
{
this.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
}
Then you have to override "OnDrawItem":
protected override void OnDrawItem(System.Windows.Forms.DrawItemEventArgs e)
{
using(System.Drawing.SolidBrush sb = new System.Drawing.SolidBrush(System.Drawing.Color.Red))
{
e.Graphics.DrawString(this.GetItemText(this.Items[e.Index]), e.Font, sb, e.Bounds);
}
base.OnDrawItem (e);
}
Note: I only tested it with "DropDownStyle" set to "System.Windows.Forms.ComboBoxStyle.DropDown", and I think behaviour changes then.
I think this article[^] covers it up better.
Hope it helps!
All the best,
Martin
|
|
|
|
|
Hi!
I encountered a problem when setting TextBox.Text variable to String which contains both right-to-left (ex. Arabic or Hebrew) and left-to-right (ex. digits) characters. The characters from this string are automatically reordered for display. For example, when I put there a String
"1" + \u05d0 + "2" + \u05e1
(four characters - two digits and two hebrew)
the TextBox displays text
"1" + \u05e1 + "2" + \u05d0
(two hebrew characters are exchanged).
What I noticed during analyzing this issue:
1. String isn't changed itself - when I print TextBox.Text in Console, it is the same as it was previously - so it is only a matter of displaying.
2. Display order is changed after setting TextBox.RightToLeft property to Yes. However, it still differs from the original one.
Is there any option to present String in TextBox as is? (in raw mode)? I've googled a lot, but unfortunately didn't find any solution.
Thanks in advance for your reply,
Tomek.
|
|
|
|
|
Hi,
I used an object of class type derived from XmlTextReader which implemented IDisposable. What member function of XmlTextReader should I call to clean up so that I can call them in the Dispose function of my derived class. If I understand correctly I really should only call Close() but do I need to call other functions like for example Flush()?
Having implemented the IDisposable pattern, I can now use my object in the form
using(MyDerivedXmlTextReader _mdXml = new MyDerivedXmlTextReader(...))<br />
{...}<br />
TIA!
I am a SysAdmin, I battle my own daemons.
|
|
|
|
|
By wrapping the class in the using statement, the Dispose method is automatically being called when the using block ends. Generally (but not always), Close is synonymous with Dispose . You can verify that by looking at the MSDN docs or using Reflector to look at the code. The Flush method generally is used to flush any data in the internal buffer to disk. Again, generally, the Close method will typically call Flush .
|
|
|
|
|
Okay now my problem:
I want to have a program (for example form1) that holds a data structure
if i click on call, form1 loads dynamically another program (showform)
shoform needs to get to the data structure in form1 to view this sturct, but how??
sry for bad english ^^
|
|
|
|
|
|
Der M wrote: I want to have a program (for example form1) that holds a data structure
if i click on call, form1 loads dynamically another program (showform)
Do you really mean different programs, or only forms (in the same program)?
If you mean different forms, this[^] article will help you.
[ 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
|
|
|
|
|
I mean diffrent Programs.
|
|
|
|