|
Hello
If you're trying to break a single class over multiple files, I should remind you that you should declare it as partial . Otherwise using the same namespace would work fine.
Regards
|
|
|
|
|
Hey guys,
I am writing a little two way chat program for fun and I am trying to get an error provider to validate the nickname text field. I have the nickname text field and login button set up within the same group box. Whenever the user clicks the "Logon" button I want to check to see if the nickname textbox is empty. If it is I want to set the error handler. Here is my code:
private void btnLogon_Validating(object sender, CancelEventArgs e)
{
if (tboxNickname.Text == "")
{
mainErrorProvider.SetError(tboxNickname, "No nickname entered.");
e.Cancel = true;
if (tboxNickname.CanFocus)
tboxNickname.Focus();
}
else
{
mainErrorProvider.SetError(tboxNickname, "");
}
}
So my problem is this. When i click the button nothing happens, until i click something on the form that is outside of the group box containing the button and text field. Can anyone tell me what is going on? Thanks in advance.
-- modified at 19:26 Tuesday 8th August, 2006
|
|
|
|
|
Put your code in btnLogon_Click method.
Remove e.Cancel = true;
btnLogon_Validating will be called if the button lost his focus.
That's the same with tboxNickname_Validating, only called if textbox lost focus.
Then use put e.Cancel = true in Form_Closing.
|
|
|
|
|
Hey all,
I'm looking for a color deviation algorithm.
I have a bitmap with a drawing and a background.
My goal is to identify all pixels matching the color of the background, and make them disappear.
My code is working fine, except for one little annoying thing...
There are some pixels (usually near the drawing edges) which are only a bit different in color from the "transparent" color.
My function gets 3 arguments: a bitmap, a transparency key, and a deviation number.
I use the following color comparison:
if ((Math.Abs(p[0] - b) + Math.Abs(p[1] - g) + Math.Abs(p[2] - r)) / 3 <= Deviation) I calculate the avg value of the differences in RGB, and compare it to my deviation parameter.
The above is an improvisation of mine, as you can probably guess.
It works for most of the pixels that I want to erase.
I can tell there's a better way (the right way ) to do this, as I'm not an expert on the image processing subject (YET ).
Soooo, anyway... I tried google, codeproject, and others, but I didn't really had a lead as for what to look for... I've tried stuff like: "Color deviation algorithm", "Pixel comparison algorithm", etc.
Could you please link me to an article / algorithm on the matter?
The right keywords I should search with would be good too.
Thanks in advance,
Shy.
|
|
|
|
|
I've had a look at the (many) Explorer bar controls available on CP, and very good they are too.
However, how do folks typically handle the right (or content) pane in such applications? Take Windows Explorer as a good example - when you select options in the Explorer Bar pane, the content pane changes and not always to the same type of pane as the previous one. Now I know I could achieve this by using layered panels, but I could see this getting pretty messy.
So my question is, how would you folks implement an application like this?
Cheers,
Martin.
|
|
|
|
|
Say I have custom class foo. I also have a class bar that inherits from foo. I want a method that returns an instance of foo and then want to cast it to bar. How can I do this? I am working with C# 2.0. This is how I imagine it working, and it compiles this way, but I get a runtime error that bar cannot be converted into foo.
public class foo
{
public string someVariable;
}
public class bar : foo
{
public string someotherVariable;
}
public static foo SomeFunction()
{
foo returnVal = new foo();
return foo;
}
public static void AnotherFunction()
{
bar barVar = (bar) SomeFunction();
}
I am almost positive that this can be done, but I can't seem to remember how to do it. I don't want to pass in some kind of reference param or Type.
|
|
|
|
|
You can't cast a foo to a bar when you never created a bar
new foo(); creates a foo not a bar so you can't cast it to a bar.
led mike
|
|
|
|
|
What you've set your code up to do is the ability to cast a bar to a foo; but you can't cast a foo to a bar unless it was already a bar to begin with that you had previously cast as a foo.
|
|
|
|
|
Any ideas of how to do something along these lines? In this scenario, foo holds a bunch of variables used in as results from some operations. I have several super classes that inherit foo that have variables that are specific output for that operation.
As an example, say foo holds a return code and input parameters for calling a Process object. bar has a variable that is assigned later on in the calling method. Another class that also inherits from foo has another unrelated variable that is also set later on by the calling function. Basically, I am trying to write a method that calls the Process object and then returns a base type of foo and then I want to be able to assign the variables that are specific to the superclasses without writing a Convert function.
Seems like there is a fairly easy way to do this, but I keep drawing blanks.
|
|
|
|
|
So inside Foo make a method, lets call it FillFoo(), you make this public and then you can now call it from anything that inherits from Foo. This function however will only fill the values you want to put in Foo. The values for bar and other derived objects can be filled with their own methods contained in their respective objects, such as FillBar(), etc...
I think thats sort of what you are trying to do...
|
|
|
|
|
Yeah, that is basically what I ended up doing. Instead of a method though I made a new protected constructor for foo that takes an instance of foo as a param. I then created a new constructor on bar that takes foo as a param and just pass it down the chain. Kinda silly, but it works. I get why .NET doesn't allow you to do what I was trying originally, but it would be nice if you could cast up the inheritance chain (foo can be cast into bar) as well as down (bar can be cast into foo).
Thanks for pointing me down the right path.
-- modified at 20:24 Tuesday 8th August, 2006
|
|
|
|
|
Can somebody tell me how to change column headers in an asp.net datagrid?
Can I use DataGridTableStyle in asp.net. how can I get my column headers to change programatically?
|
|
|
|
|
What exactly you want to do in datagrid header?
BTW this you better can put in the asp.net forum.
Best Regards,
Apurva Kaushal
|
|
|
|
|
I just wanted to change header names in the datagrid as the user selects certain things from the drop down box. I figured it out today the code is the following:
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemIndex == -1)
{
e.Item.Cells[0].Text = "Country";
e.Item.Cells[1].Text = "Rate";
e.Item.Cells[2].Text = "NPA code";
e.Item.Cells[3].Text = "Carrier";
e.Item.Cells[7].Text = "less 46%";
}
|
|
|
|
|
if i have table with one col
salary
-------
5
9
7
i want to make comboBox for each record in the database
the probelm now how can make (onchange) even for each comboBox
and save direct to database ...
plz help
Palestine
|
|
|
|
|
Keep your posting in one thread...!!!
|
|
|
|
|
Hey guys,
Could someone tell me how i can get a list of files of a particular type within a directory as well as its subdirectories. I use the Directory.GetFiles Method to get alist of all the files in a location, however, iam having a hard time figuring out to get all the files of particular type from the subdirectories too.
Thanks in advance!
|
|
|
|
|
There's no build in support for recursively searching subdirectories, so you have to do it on your own but that shouldn't be to hard Use Directory.GetDirectories to get all sub directories and recursively call your search method.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
|
Hi,
Create a recursive function which will loop a directory and get a file with specific extension. Call the same function with in the function if the directory has sub directories. Let me know if you need the code for this.
Ram
|
|
|
|
|
I have the labelEdit property of a listview set to true, but only at infrequent, and seemingly random occasions am I actually able to edit the contents of a cell.
|
|
|
|
|
I have a class, IRC, which contains a variable StreamWriter, and a property, Channel, which is associated with the class, ChannelInformation.
ChannelInformation has a function, Join(). How can I call StreamWriter from inside Join() without adding delegates? How does the .NET Framework solve this?
Thanks! ;P
|
|
|
|
|
When you say associated with the class ChannelInformation what do you mean by that?
And why not just pass the StreamWriter by reference into Join when you call it?
|
|
|
|
|
if i have table with one col
salary
-------
5
9
7
i want to make comboBox for each record in the database
the probelm now how can make (onchange) even for each comboBox
and save direct to database ...
plz help
Palestine
|
|
|
|
|
I would do it something like this:
Have a foreach statement. Inside that foreach statement create a new combobox. Then add the item to the combobox. You would need to make a method that was generic enough so that you could use it for all of your comboboxes that you make. This method would handle your On Selected Index Change Event.
//thrown together, don't trust it to work without checking it over...
foreach(datarow dr in table[0].rows)
{
ComboBox cb = new ComboBox();
//Make sure you give cb a unique name so that you can tell it apart from the other combos.
cb.items.add("Pass in your value from the datarow here");
cb.WhateverThatChangeSelectedIndexEventIs += ThatEventITalkedAboutUpAbove();
//I'm sure you can manage to place the combobox on the form in a more exact way...
this.controls.add(cb);
}
Should be something like that.
|
|
|
|