|
Hi
Can anyone tell me how to generate a date in random in the interval of two dates (Max date and the Min date)...
Please anyone suggest the answer soon as my due date is nearing
Thx
Anjum
|
|
|
|
|
search on google for "c# random" it'll tell you about the random class ... the random class takes a min int and a max int ... the rest you just need to code.
|
|
|
|
|
I think you can do that with Random Class and DateTime Struct
you can get number of available days in each month with DateTime.DaysInMonth method for correct random date generating and then simply put your generated random numbers from random class in the Constructor of DateTime struct and you will have it.
|
|
|
|
|
1) Calculate the number of days between MIN & MAX.
2) Get random number within that range.
3) Add the random number to MIN.
TimeSpan ts = DateTime.Parse("12/31/2006") - DateTime.Parse("1/1/2006");
Random r = new Random();
int randomDays = r.Next(ts.Days + 1);
DateTime randomDate = DateTime.Parse("1/1/2006").AddDays(randomDays);
MessageBox.Show(randomDate.ToShortDateString());
|
|
|
|
|
It means that when user press F1, help of the application will load in a special form. How can I do this?
Pls help!
|
|
|
|
|
Hi
You just use c# namespace
using System.Runtime.InteropServices;
Process.Start("Test.Chm")
so you can call anykind file using the above code and also connect to internet use these code
Sak
|
|
|
|
|
Thanks Sak,
What is the Process is?
|
|
|
|
|
See System.Windows.Forms.Help.ShowHelp
|
|
|
|
|
Hi All,
I have a smart part views which is calling a user control named "A". I want to call a another user control named "B" from previously loaded user control "A". Is that possible or otherwise i have to change the user control "A" to a smart view.
Please anyone help me in this, if possible with a sample code...
Thanks in advance,
Uma Shanker.K
|
|
|
|
|
when i double click in listview i want to do something i have 4 item i listview
but how i get item line 1 is id? line2 id? but idont know to use method
if (listview1.???????? = =1) { do somthing }
srry i begin
|
|
|
|
|
you can use listView.Items[...] property generally
in double click
and ListView.SelectedItems[...] Property or List.View.SelectedIndices[...] which the first one returns the selected ListViewItem and another one returns the index of the selected ListViewItem
and if you do not use multi selection you can simply access to the selected Item like
ListView.SelectedItem[0]
<br />
<br />
void listView1_DoubleClick(object sender, EventArgs e)<br />
{<br />
MessageBox.Show((sender as ListView).SelectedItems[0].Text);<br />
}<br />
good luck
|
|
|
|
|
|
can you give some hints about what exactly you mean about id?
Using the ListBox is very similar except it has too more ListBox.SelectedItem and ListBox.SelectedIndex Properties and another difference is it will return an object which must be casted to what you put inside for using it after retrieving from the list
and about showing things in ListBox
when you add something in listbox it simply use your object's ToString method for showing that in the list So all things you want to show from your class in the listBox must be set into overridden version of ToString method so it can show that.
Hope this one helps
|
|
|
|
|
As title really, i have an app with the ability to drag an item from a list box onto another grid type control, i can drag and drop no problem, i can also get the x,y coords of the mouse within the control when not dragging, but i need to get them when i have dropped the item onto the grid control. the problem is, the coords i am getting are not the withing the control but the screen ( i think ) any ideas how i can covert to the controls coords or how to get the coords from the control ??
Thanks in advance
Lee
|
|
|
|
|
hi
Point point = MyControl.ScreenToPoint(new Point(e.X, e.Y));
regards
|
|
|
|
|
i cannot see a function ScreenToPoint i have PointToScreen and PointToClient but not the otherway round ?? am i missing something here ??
Thanks
|
|
|
|
|
you want PointToClient
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
thanks, i finally sussed it after reading the first response... i just used
Point pt = Control.PointToClient( new Point( e.X,e.Y ) );
Thanks for the responses..
|
|
|
|
|
Hi All,
I have some block that occur in my catch ( try...catch ), this block is repeats a lot of time ( with different message but beside this message all the rest are the same ).
In C++ i would replace this block with some #define - but in C# i cant use ( of course ) this define.
My question is is there is something else that i can use to save line code in my project ?
Can i use something else beside writing all those 4 line in the block again and again and .... again....
I know that i can write some method and call it all the time - but i looking some other way.
Thanks for any help
|
|
|
|
|
No there is not.
"#define IDENTIFIER" is available for conditional stuff, there is no DEFINE
for code substitution.
go with the method !
And if you want to show the exception, show it in its entirity, that is
with ToString(), everything else sucks.
What's in those four lines anyway ?
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Yanshof wrote: I know that i can write some method and call it all the time
Well, why not?
Yanshof wrote: but i looking some other way
Why? What advantage do you think you will get?
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
"I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless."
My website
|
|
|
|
|
Colin Angus Mackay wrote: Why? What advantage do you think you will get?
#define in C/C++ is a code obfuscater. Obfuscated code is job security.
--
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
|
|
|
|
|
You can use #if, #else if #else inside the code, and you can #define some constants either at the very beginning of the file or in the project properties
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Use a method and/or derive your own type of Exception.
On the other hand... The "C preprocessor" can be used with any type of text file, not just C/C++ source files. I do use it with C#, but only to prove the point.
|
|
|
|
|
Hi All,
I am developing an application where a vehicle's route will be tracked by Microsoft MapPoint. Recently, it gives me an error message box - "Server Busy" and it has 2 option buttons "Switch to" and "Retry".
I have searched in Google and they say that it occurs when - the COM object(here MSMapControl) is not responding within a time period. They all suggest to set
"app.OleRequestPendingTimeout" to a higher value. But this is in Visual Basic and this object is not supported in C#.
Can anyone tell me how can i do this in C# ?
Thanks
Chayan
|
|
|
|