|
Well.. I suspect that posting this doesn't help... I think the error might be somewhere else in my code, or in the .NET framework..
here's the code in three different versions that compiles perfect:
[no1]
public GradientControl()
{
this.colorGradient = new ColorGradient();
this.colorGradient.GradientChanged += new EventHandler(colorGradient_GradientChanged);
}
[no2]
public GradientControl()
{
this.colorGradient = new ColorGradient();
this.colorGradient.GradientChanged += colorGradient_GradientChanged;
}
[no3]
public GradientControl()
{
this.colorGradient = new ColorGradient();
this.colorGradient.GradientChanged += delegate(object sender, EventArgs e) { /*code*/ }
}
|
|
|
|
|
_eulogy_ wrote:
[no1]
public GradientControl()
{
this.colorGradient = new ColorGradient();
this.colorGradient.GradientChanged += new EventHandler(colorGradient_GradientChanged);
}
Is ColorGradient a class you have declared? If so, did you mark the event with the 'event' keyword?
What is the event type for GradientChanged? It could be something wrong somewhere else like you stated.
_eulogy_ wrote:
no2]
public GradientControl()
{
this.colorGradient = new ColorGradient();
this.colorGradient.GradientChanged += colorGradient_GradientChanged;
}
This is definately not going to work
_eulogy_ wrote:
[no3]
public GradientControl()
{
this.colorGradient = new ColorGradient();
this.colorGradient.GradientChanged += delegate(object sender, EventArgs e) { /*code*/ }
}
This might only work in C# 2.0, but I dont think you put the parameters for anonymous delegates in C# 2.0
-
Drew
|
|
|
|
|
The ColorGradient is a class I've made.. If I didn't mark GradientChanged with the event keyword I would get a compile time error. The gradient changed is an EventHandler (as you can see in no1)..
this.colorGradient.GradientChanged += colorGradient_GradientChanged;
works as hell... It's a new syntax..
this.colorGradient.GradientChanged += delegate(object sender, EventArgs e) { /*code*/ }
this also works as hell.. You have to put the parameters there, or else you can't access them!
I've found the problem though... It seems like it was caused by an inconsistency in how whidbey stores the gui objects created with the visual editor...
|
|
|
|
|
i got this Error when adding a component in my progect
"Failed to import the activeX control"
how can i solve this ?
|
|
|
|
|
I want to insert a hugh data table to oracle database. currently i use for loop to go throuh each row of table and use insert sql statement to insert row to oracle database.
Any one has ohter easy way to do this?
Thanks for help.
|
|
|
|
|
I have a string
str = "145.35" and want to convert it into a float value.
Float.Parse(str)
and the result is 14535.0
I tried some ways already but there must be a way to convert it correctly. Does anybody know a way out ?
|
|
|
|
|
You can always try Convert.ToSingle("145.35") ...
|
|
|
|
|
str is filled with an unknown value. 145.35 is an example only.
|
|
|
|
|
I was using "145.35" as an example as well. BTW, what is your locale? This does play a part into how the conversion routines try to to parse things. Is "." the decimal delimiter or the thousand delimiter for you?
ps. This does bring up an quirky point: Is Convert.ToSingle meant to be the IEEE supported float conversion while Single.Parse is the locale specific one?
|
|
|
|
|
It's the decimal one.
Single bring the same problem.
|
|
|
|
|
I've written a lot of code converting string values that are clearly "float like" and never had a problem. I guess the problem is deeper. I would investigate exactly what is the string you are feeding into it because I simply can't reproduce your problem. The only other thing I can think you are running into is some bad percision mojo but your example isn't sufficient to show it.
example code:
using System;
namespace tlarsen
{
public class test
{
public static int Main()
{
string s = " 145.35 ";
float f = Convert.ToSingle(s);
Console.WriteLine("s = " + s);
Console.WriteLine("f = " + f.ToString());
Console.WriteLine("1 + f = (should be 146.35) : " + (f + 1));
return 0;
}
}
}
|
|
|
|
|
Due to the local settings, application demands "," as delimeter not the "."
Now it works.
|
|
|
|
|
float.Parse(str) method should also work. Perhaps you might have committed some small mistake here and there. For testing it, create a new Windows Form project and place a button1 on that. In the click event-handler, put the following code:
private void button1_Click(object sender, System.EventArgs e)
{
string str = "145.35";
float x = float.Parse(str);
MessageBox.Show(x.ToString());
}
It works properly and the MessageBox shows the correct value of float variable as "145.35". If you use x in some expression such as x = x*2, again it will use the correct value. In the debug mode, when you check the value of x, again it shows the correct value. So please ensure that you use the proper coding, otherwise there is nothing wrong in the method.
|
|
|
|
|
Hi!
Is there a way of making a string html compliant (i.e. replacing german umlauts with the appropriate hex code), without hardcoding each character's translation.
|
|
|
|
|
Check out System.Web.HttpServerUtility.HtmlEncode(string)
Hope this helps
|
|
|
|
|
Thanks a lot! That was exactly what I meant. Although I must say that HttpServerUtility is only usable from within an ASP.NET application, for normal Windows apps HttpUtility has to be used.
|
|
|
|
|
Thank you for spending time here
You know in Visual Studio, when you move an object around such as a textbox, the cursor is changed to an arrow with a rectangle (the rectangle's size is equal to the size of the textbox) to indicate the new location of the textbox when you release the button..
I can change the cursor shape and all, but how do i draw that custom rectangle?
please help me out.
Elapid For The Win
|
|
|
|
|
anyone?
Elapid For The Win
|
|
|
|
|
What do you mean "custom rectangle"? You mean around a control? The designer is responsible for drawing that feedback mechanism (the border + handles). As for how they do it, there is a bunch of stuff inside System.Drawing that helps.
|
|
|
|
|
Thank you Tom for your reply.
I mean when you move a control (i.e Textbox) the Cursor is changed to an arrow with a rectangle which would show users that if they release the mouse, then the textbox will be moved in the place of the rectangle.
What I don't know is how to draw a rectangle with the cursor
please help me out
Elapid For The Win
|
|
|
|
|
Actually, the cursor doesn't change at all. What happens is the MouseMove event, the mouse buttons are polled to see if one is held down. If so, then a box representing the size of the control is drawn on the form, under the cursor.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Thank you Dave.
I got that done
Elapid For The Win
|
|
|
|
|
Hi
I have a custom property updating another custom properety the code is as follows
<br />
public enum CodePageType { None, Swift, ASCII, Trade };<br />
public string RegularExpP<br />
{<br />
get { return regularEx; }<br />
set { regularEx = value; }<br />
}<br />
[Category("Custom Properties")]<br />
[DefaultValue(false)]<br />
public CodePageType Validate<br />
{<br />
get <br />
{<br />
if (type == CodePageType.ASCII)<br />
{<br />
RegularExpP = "Exp1";<br />
}<br />
if (type == CodePageType.None)<br />
{<br />
RegularExpP = "Exp2";<br />
}<br />
return type;<br />
}<br />
set {type = value;}<br />
}<br />
Now when i select the validate property the RegExpP property is set in the UI but its not getting updated in the Form1.Designer.cs Page.But its getting updated only the second time, and this time it sets the previous value i selected hat could be the problem
Regards
Deepak.s
|
|
|
|
|
I am working on a windows app and having some trouble getting type information by just the name. I have to load a file that will have several different type names (Type.FullName). When I call Type.GetType(fullname), it is always returning null, even for types that I would assume it wouldn't like System.Windows.Forms.TextBox. The only way that I can get it to return a type is if it is a local assembly, put it in format of 'Fullname,AssemblyName'. If it is not a local assembly, then I have to put it in the format of 'AssemblyQualifiedName'. This is ok, but it kinda screws some of the useability of the app. Does any one know a way around this? I know that I can use just the full name of the type if I am doing straight from the assembly reference (Assembly.GetType(fullname)), but I would prefer it if I didn't have to have a reference to the assembly to get the type (even though the assembly will be loaded at this point anyways). Any ideas would be greatly appreciated?
|
|
|
|
|
Can I ask what you are attempting to do? Type information is somewhat non-human friendly just because it is designed to be that way. Why are you asking the user for a type which may or may not be in any loaded assembly? Maybe you should instead offer a list of loaded types with a filter?
|
|
|
|