|
Jim Crafton wrote: System.Windows.Forms.Application.UserAppDataPath
from another thread
I believe you need to avoid doing that. Since it is a static property, it will be specific for the current thread. Try to pass the value to worker thread as a parameter when you start it.
Best wishes,
Navaneeth
|
|
|
|
|
Hello!
Im trying to figure out how I get the dates for the first and last day of a given year and week.
For instance:
year: 2009 week:53 = 2009/12/28 - 2010/01/03
year: 2010 week:1 = 2010/01/04 - 2010/01/10
Does anyone know how to achieve this?
|
|
|
|
|
Use the DateTime structure[^] to create an object of the type you require, then adjust the values to get the dates you are looking for.
|
|
|
|
|
Hello and thanks for your reply. I don´t see how it would be that easy though.
Could you give a pointer of how you would solve my problem with datetime-class?
I´ve been trying to use System.Globalization.Calendar with AddWeeks etc, but have yet to make it work.
|
|
|
|
|
livez wrote: Could you give a pointer of how you would solve my problem with datetime-class?
Create a DateTime object with the relevant date, add or subtract one day until it's the first day of the week (i.e Sunday or Monday), save that date. Add one day until it's the last day of the week, save that date. Look at the DateTime members to see what is possible.
|
|
|
|
|
"Create a DateTime object with the relevant date" But its the relevant date I dont have. I have a year and a weeknr. How do I create a relevant datetime-object with that?
|
|
|
|
|
Create a DateTime(year, 1, 1)
Adjust by day until the day is Thursday to get it to week 1
Add 7 x week number
Adjust day back and forward to find Monday and Sunday
|
|
|
|
|
|
got it working with your suggestion (with a slight adjustment), thanks!
|
|
|
|
|
Try this -
CultureInfo info = Thread.CurrentThread.CurrentCulture;
DateTime dt = info.Calendar.AddWeeks(new DateTime(YYYY, MM, DD), x); where x is no of weeks.
The interesting thing to note here is that if you use the first day of the first week of the previous year (i.e. 2008/12/28) evertything works fine. If you use new DateTime(2009, 1, 1),you would get that date plus 53 weeks which would not help you as per your query. Hope that makes sense .
|
|
|
|
|
DateTime does not appear to handle week of year at all - much to my suprise. Fortunately, I had to implement this for a real-time project many years ago. For the full rules, look for ISO-8601 which is the standard reference for dates and times, but:
1) Week number is 1 - 53.
2) Weeks start on Monday.
3) Week one is always the week with the first Thursday of the new year. I.e., if January the 1st is a Monday, Tuesday, Wednesday or Thursday, it is in week 1. Otherwise it is in the final week of the previous year (which could be week 51, 52, or 53 dependant on when week 1 was in that year).
Yes, this means that December 29th, 30th and 31st could be in Week 1 of the new year!
All those who believe in psycho kinesis, raise my hand.
|
|
|
|
|
This might help:
http://en.wikipedia.org/wiki/ISO_week_date[^]
It tells you how to calculate the week number for any given date, so it shouldn't be too hard to "reverse engineer" it to come up with the date corresponding to a given week number.
|
|
|
|
|
Thanks, Ill check it out!
|
|
|
|
|
I already got my code to work.
|
|
|
|
|
Richard MacCutchan wrote: I already got my code to work.
Teacher's pet!
|
|
|
|
|
Yeah and I brought an apple today.
|
|
|
|
|
I have 'Form1' and 'Form2'. Form1 opens up Form2 and Form2 brings up a FolderBrowserDialog (called m_MyBrowser). For the folder strucure to show properly in fbd I have to open this dialog on a different thread like this:
Thread aThread = new Thread(new ThreadStart(ShowFolderBrowser));
aThread.SetApartmentState(ApartmentState.STA);
aThread.Start();
private void ShowFolderBrowser()
{
m_MyBrowser.SelectedPath = string.Empty;
if (m_MyBrowser.ShowDialog() == DialogResult.Cancel)
return;
else
txtBxLocation.Text = m_MyBrowser.SelectedPath;
}
My problem is that I want the m_MyBrowser to be modal and top most (relative to Form2), but since I had to open it in another thread I can't get it to work by simply calling the ShowDialog() method.
Does anyone here have any ideas on how to get it modal?
|
|
|
|
|
I seem to have left my brains in the other pants...
ShowDialog(IWin32Owner) will do the trick.
|
|
|
|
|
Hello,
i have a treeView component where a ContextMenuStrip is already assigned to it (ex. contextP)
now, i want to drag a node from one place to another in the treeView.
when i do so, i call the DragDrop event which has all my function's according to my needs.
in this event, i would like to call a different ContextMenuStrip named contextD.
i thought of using
<br />
.<br />
.<br />
.<br />
contextD.Show(Point pt);<br />
.<br />
.<br />
.<br />
<br />
private void contextD_Opening(object sender, CancelEventArgs e)<br />
{<br />
ToolStripMenuItem itemMove = (ToolStripMenuItem)contextDrag.Items["ctextMoveItem"];<br />
ToolStripMenuItem itemCopy = (ToolStripMenuItem)contextDrag.Items["ctextCopyItem"];<br />
ToolStripMenuItem itemCancel = (ToolStripMenuItem)contextDrag.Items["ctextCancelItem"];<br />
}<br />
but when the opening event has finished, the main code continues, and the contextD is still shown, regardless to my selection.
how can i make the contextD to stay on, depending on my selection in the menu to continue my flow (do event's etc.) ?
then of course, how to close it when im finished with it ?
thanks
Eyal
|
|
|
|
|
Hi Eyal,
I have a lot of experience working with TreeViews. Reading your description I can't really figure out what the relationship of the ContextMenuStrip and moving/copying/cancelling drag is in relationship to what you are doing with nodes.
Are you implying you want to put up a context menu strip during a drag operation : then let the user select move/copy/cancel from the context menu ?
If this is correct, would you want to put this context menu up at the moment the drag started (just after the call to 'DoDragDrop) ... or maybe when the drop target has been selected and DragDrop is being executed ?
Please describe further what your goal is here.
Using key combinations to determine whether a Drag Move or Drag Copy is being done is a fairly standard practice (usually detected in the source's ItemDrag event).
And, of course, you have the QueryContinueDrag event to use to allow cancelling in the DragSource's code in response to mouse or key events : [^]
best, Bill
"Many : not conversant with mathematical studies, imagine that because it [the Analytical Engine] is to give results in numerical notation, its processes must consequently be arithmetical, numerical, rather than algebraical and analytical. This is an error. The engine can arrange and combine numerical quantities as if they were letters or any other general symbols; and it fact it might bring out its results in algebraical notation, were provisions made accordingly." Ada, Countess Lovelace, 1844
|
|
|
|
|
Hello Bill,
thanks for your replay.
to be more accurate what i intend to do is after the drop target has been selected, then put up a context menu strip with the relevant options.
when the user selects copy for example, invoke the copy event which copies the source to the target..
and if the user selects cancel, do nothing
the event's are something i already have in my program, the only thing missing is this context menu strip option the will activate them properly.
have i made my self more clear ?
thanks a lot
Eyal
|
|
|
|
|
Hi Eyalle,
I think there is a "structural problem" here, but I have to disclaimer what I'll say by letting you know I'm working with a 3rd. party WinForms tree control whose behavior may be different than the standard WinForms TreeView, and I don't have time to go back and test against the standard WinForms TreeView.
The problem as I see it is the rather unique dynamics of drag and drop : first the control the drag is coming from continues to capture the mouse until Drop time.
Yes you can put up a context menu strip, or a menustrip, in the DragDrop of the drop-target control event, and set some global variable by selecting one of its items : the problem seems to be it runs on another thread : it's not modal : it doesn't block the rest of the code running in your DragDrop handler from proceeding : in fact, if you put a Console.WriteLine in your context menu selectItem code to print out your choice : you'll find it's written out after the DragDrop completes.
I have one prototype I wrote where I completely bypassed all of the regular WinForms drag and drop : in that prototype I was successful, in doing exactly what you are describing here (and with a much better drag-drop preview image, and a nice option menu that stuck around until you dismissed it). If I have the time I intend to publish that technique here on CP.
Perhaps one of our resident "gurus" will "weigh in" here with some wisdom
best, Bill
"Many : not conversant with mathematical studies, imagine that because it [the Analytical Engine] is to give results in numerical notation, its processes must consequently be arithmetical, numerical, rather than algebraical and analytical. This is an error. The engine can arrange and combine numerical quantities as if they were letters or any other general symbols; and it fact it might bring out its results in algebraical notation, were provisions made accordingly." Ada, Countess Lovelace, 1844
|
|
|
|
|
Hi Bill,
Thanks again for you're time.
it will be great if you will have the time to post that code, im sure it will help lot's of programmers..
Happy holiday's
Eyal
|
|
|
|
|
Hi Eyalle,
Happy Hanukkah !
eyalle wrote: it will be great if you will have the time to post that code, im sure it will help lot's of programmers..
It will be a few months before I get to this, probably.
Consider the many benefits built into "native" drag-and-drop including (with effort) drag-dropping stuff from one application into another, interacting with the clipboard, the whole DataObject functionality built-in, dropping files or whatever to the desktop, etc.
best, Bill
"Many : not conversant with mathematical studies, imagine that because it [the Analytical Engine] is to give results in numerical notation, its processes must consequently be arithmetical, numerical, rather than algebraical and analytical. This is an error. The engine can arrange and combine numerical quantities as if they were letters or any other general symbols; and it fact it might bring out its results in algebraical notation, were provisions made accordingly." Ada, Countess Lovelace, 1844
|
|
|
|
|
Simple question:
How do I position an MDI child form inside the parent form when you call the child form?
Thanks.
|
|
|
|
|