|
textBox1.DataBindings.RemoveAt (0);
123
|
|
|
|
|
but, it is not working.......
Jo
|
|
|
|
|
For my game I created a class called "Integer" to use with by ComboBox. For somereason the ComboBox says "TANK.Integer".
<br />
class Integer<br />
{<br />
public int value;<br />
<br />
public Integer(int value)<br />
{<br />
this.value = value;<br />
}<br />
<br />
public int Value<br />
{<br />
get<br />
{<br />
return this.value;<br />
}<br />
}<br />
<br />
new public string ToString()<br />
{<br />
return this.value.ToString();<br />
}<br />
}<br />
In the constructor that is used in Application.run I call:
<br />
MessageBox.Show(Game.grid_height_configurations[0].ToString()); <- An array of "Integers"<br />
It says "TANK.Integer" instead of calling Integer's ToString method. It's probably something small.
|
|
|
|
|
In your integer class, you should override the ToString() method:
<br />
public override string ToString()<br />
{<br />
return this.value.ToString();<br />
}<br />
|
|
|
|
|
Heh I was right it was something small. Thanks.
|
|
|
|
|
and you should not ignore (or suppress) compiler warnings either. it did tell you what was probably wrong.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
There were no compile error/warnings. Whenever I make a program I make it a practice to have no compile errors/warnings.
|
|
|
|
|
object.ToString() is an existing virtual method; adding a ToString() method to some type therefore
requires either the "new" or the "override" keyword, and such is indicated by the C# compiler in all
Visual Studio versions I have seen so far, provided the warning level is set sufficiently
high (I run mine at the maximum value, which is 4), and the specific warning is not suppressed.
The exact message is:
warning CS0114: 'XXX.ToString()' hides inherited member 'object.ToString()'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
I'm having a strange problem in my project that I do not understand.
I have a bunch of buttons in a master page that every page uses. When the user presses return in one of my search field (to query data) in a page that uses it, the page_load of the master page fires, and for some reason, the first button is being somehow clicked and the user is redirected to the page of the first button in the master.
Here is the code in my master page:
void Page_Load(object sender, System.EventArgs e)
{
string path;
if (!IsPostBack)
{
path = Request.Url.Host;
// If the user_id was not set, this means that the Default.aspx form
// was not run and no valid credentials. Redirect user back to the Default page to validate
// credentials. If running on a local host, don't worry as this is the developer.
if (path != "localhost")
{
if (Session["user_id"] == null)
{
Response.Redirect("Default.aspx");
}
}
}
return;
}
protected void test()
{
return;
}
protected void imgbtn_accounts_Click(object sender, ImageClickEventArgs e)
{
Response.Redirect("AccountList.aspx");
}
imgbtn_accounts_Click is always being activated.
Here is the asp code in the master page:
asp:ImageButton ID="imgbtn_accounts" Tabindex="1" style="position:absolute; left: 270px; top: 41px;" ImageUrl="~/Images/Accounts.gif" runat="server" OnClick="imgbtn_accounts_Click" />
When I take away the OnClick="imgbtn...", the behavuior goes away but then my imgbtn_accounts becomes useless.
Does anyone have any idea why this is occurring?
Thanks,
Garry
|
|
|
|
|
I need to create this program and needs to have if, else statements.
Could you please help me?
I want to create a program that will look like that?
Welcome to HollowRectanglePrinter!
How many columns wide should the rectangle be? 6
How many rows tall should the rectangle be? 4
Here you go:
******
* *
* *
******
|
|
|
|
|
OK - for a starter if/else statements aren't loops. They're conditional statements. Next, we won't do your homework for you - and this is so obviously a homework assignment. Finally, if you can't solve a basic problem like this quickly then you really shouldn't be aiming at a career in programming.
|
|
|
|
|
(I agree that it looks like homework.)
Loops? Plural? I can do that without loops.
P.S. Without conditionals as well.
P.P.S. And no recursion either for that matter.
|
|
|
|
|
Some fancy pants string formatting?
|
|
|
|
|
Mostly PadRight, with a smattering of Replace thrown in.
And to think I wrote a version last year using four for loops; oh the shame!
|
|
|
|
|
Okay - I've got a working solution without a single loop or conditional statement, nor does it use recursion. Probably not the most elegant solution, not as compact as Guffa's solution, but interesting none the less.
|
|
|
|
|
I'll show you mine if you show me yours....
In the interest of being the smart-ass brown-noser in the class I used line drawing characters rather than asterisks. Anybody can use asterisks.
System.Console.WriteLine
(
"\u250C".PadRight ( Width - 1 , '\u2500' ) + "\u2510\n" +
"".PadRight ( Height - 2 , '@' ).Replace
(
"@"
,
"\u2502".PadRight ( Width - 1 ) + "\u2502\n"
) +
"\u2514".PadRight ( Width - 1 , '\u2500' ) + "\u2518"
) ;
|
|
|
|
|
I suspect your solution is printing one character too wide.
My solution is not so compact:
private static void Main(string[] args)
{
Console.Write("Width:");
int width = Convert.ToInt32(Console.ReadLine());
Console.Write("Height:");
int height = Convert.ToInt32(Console.ReadLine());
string end = new string('*', width);
string middle = string.Concat("*", new string(' ', width - 2), "*", Environment.NewLine);
string fill = new string('-', height - 2);
fill = fill.Replace("-", middle);
Console.WriteLine(end);
Console.Write(fill);
Console.WriteLine(end);
Console.ReadLine();
}
|
|
|
|
|
In what I posted I use width-1 so it's not a character too wide. (Pad only adds enough characters to satisfy the requested length.)
I've never looked at constructors for string so I didn't think of that, but
"".PadRight ( width , '*' )
results in the same thing as
new string('*', width)
I suspect the constructor is more efficient.
Another tool for the toolbox, thanks.
|
|
|
|
|
Letting the replace do the looping is an interresting idea. The string constructor can do some looping too.
int w=6,h=4;Console.Write(("h"+new string('w',h-2)+"h").Replace("h",new string('*',w)+"n").Replace("w","*"+new string(' ',w-2)+"*n").Replace("n", Environment.NewLine));
Experience is the sum of all the mistakes you have done.
|
|
|
|
|
StringBuilder.Append will do that as well, leading me to suspect that the string constructor uses a StringBuilder. Stepping into the source code should confirm it.
|
|
|
|
|
I doubt that. I believe that the string constructor does something much less complicated than using a StringBuilder. It probably just allocates the memory needed for the string and fills it with the character. Also, the StringBuilder returns a finished string object, so it would be complicated to merge the string object being created with the string object returned from the StringBuilder.
Experience is the sum of all the mistakes you have done.
|
|
|
|
|
|
It's fun to obfuscate homework.
int w=6,h=4;h*=w;for(int i=h;i>0;Console.Write("*\r\n ".Substring(--i%w==0|w==i%w+1|w>i|h<i+w?0:3,i%w==0?3:1)));
Experience is the sum of all the mistakes you have done.
|
|
|
|
|
Oh no! You didn't use Environment.Newline! The world is going to end!
|
|
|
|
|
PIEBALDconsult wrote: The world is going to end!
The world is going to \r\n!
Experience is the sum of all the mistakes you have done.
|
|
|
|