|
This question has been asked hundreds of times, try searching Google[^], articles, or the forums.
I'm going to become rich when I create a device that allows me to punch people in the face over the internet.
"If an Indian asked a programming question in the forest, would it still be urgent?" - John Simmons / outlaw programmer
|
|
|
|
|
How can i change the system date style formate through code.
I have a project when it starts it compare the current date withe the condition date is the date formate is wrong it give error plz help me out.
|
|
|
|
|
|
Thanks for providing such a good link.
But my problem is not getting system data formate.
Because in Microsoft.Win32 Api there is method
GetSystemDateFormate
but there is not Setting the System Date formate
Can you help me out form this problem.
|
|
|
|
|
You shouldn't change the system's format!
Instead:
1. Retrieve the current date
2. Reformat it to the format you require
3. Compare
If you use the DateTime.Parse() method you shouldn't even need to do this as it will handle all date and date/time formats for you.
|
|
|
|
|
You asked the same question yesterday and were informed that this was not a good idea back then. Why do you think you'll get a different answer today?
The simple answer is that your application should not change the behaviour of the system to suit itself - this is a bad thing to do because you are upsetting the customer experience of the system. Instead, you need to bite the bullet and actually do some work yourself - if your code requires a particular date format, use the DateTime class to manage this in your code. This is the responsible, professional thing to do and you could have achieved this in the time you've spent faffing about trying to get people to tell you how to upset your users.
|
|
|
|
|
How to remove the databinding of the textbox control at runtime?
Jo
|
|
|
|
|
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.
|
|
|
|