|
Hi,
if you need to access a Control from a thread that did not create the Control, then
you need to use Control.InvokeRequired and Control.Invoke()
you can find many examples of this everywhere, including in CP articles; there
is an example at the end of my Sokoban article.
|
|
|
|
|
Use this instead:
lblInfo2.BeginInvoke((ThreadStart)delegate
{
lblInfo2.Text = "whatever";
});
That will invoke the text setter on the correct thread.
If you find yourself doing lots of Control.BeginInvoke or Control.Invoke calls, opt instead to use a BackgroundWorker component. Much simpler and cleaner.
|
|
|
|
|
Thanx guys, this thing is a lil bit tough for me rt now. I will get back to the prob later.
|
|
|
|
|
Ok, continuing on the context of executing reflected code...
Is there any way of adding a web reference in runtime?
Alternatively, what options do I have on invoking a web service without adding the web reference?
Thank you
Gonçalo A.
|
|
|
|
|
Well, you could always create the SOAP request yourself and send it yourself.
|
|
|
|
|
Hi
How can read the characters from Stream and write to a directory. Could any one please tell me.
I tried with this but I am getting error: UnAuthorizedException. Could anyone tell me where is wrong here?
string location = di.FullName + "/ec284451";
DirectoryInfo pub_di = new DirectoryInfo(location);
pub_di.Create();
FileStream fwrter = new FileStream(location, FileMode.Open);
// Allocate byte buffer to hold file contents
byte[] inData = new byte[4096];
// loop through reading each data block
// and writing to the request stream buffer
int bytesRead = respStream.Read(inData, 0, inData.Length);
while (bytesRead >0)
{
fwrter.Write(inData, 0, bytesRead);
bytesRead = respStream.Read(inData, 0, inData.Length);
}
Thanks
Aruna.G
|
|
|
|
|
I think you'll need to create file objects in the directory, writing the bytes to those files. Files can be created using the File.Create static method.
|
|
|
|
|
You can only write on the server, not the client, and ASP.NET is not allowed access to the file system above the root of the web app. So, you have to write to locations underneath the root of your website.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
In C# how would you do this? Can you?
I am working in C++/CLI with Windows Forms. No one in the C++/CLI forum was aware of a way to tell where the mouse is pointing when the helpprovider event is called.
I want to have my compiled html help point to a topic specific to where the mouse is pointing (like as a menu item) but I can't seem to determine which control the mouse is hovering over.
My C++/CLI code is below.
private: System::Void FrmMain_HelpRequested(System::Object^ sender, System::Windows::Forms::HelpEventArgs^ hlpevent)
{
Point pt = this->PointToClient(hlpevent->MousePos);
Control^ requestingControl = dynamic_cast(sender);
Control ^ctrl = this->pt;GetChildAtPoint(pt);
Control ^ctrl2 = this->pt;ActiveControl;
Point ptMI = this->menuMainForm->PointToClient(hlpevent->MousePos);
Control ^ctrlMI = this->menuMainForm->GetChildAtPoint(ptMI);
Point ptMenuHelp = this->miHelp->DropDown->PointToClient(hlpevent->MousePos);
Control ^ctrlMenuHelp = this->miHelp->DropDown->GetChildAtPoint(ptMenuHelp);
if( File::Exists(this->pt;helpProvider->HelpNamespace ) == true)
{
Help::ShowHelp(this, this->helpProvider->HelpNamespace);
}
}
ctrl is the form itself and crtl2 is the last active mdichild in my application.
requestingControl returns the form (same as ctrl)and not the item the mouse is over.
ctrlMI and ctrlMenuHelp are undefined.
Hope someone can help
Programmer
Glenn Earl Graham
Austin, TX
modified on Monday, January 07, 2008 4:03:51 PM
|
|
|
|
|
Hi Glenn
I tried out a few things and here's what I came up with.
If you've got a MenuStrip (e.g. File, Edit, View, etc.) and you're trying to see if the mouse is over a particular menu item (e.g. the File->Exit), you can do it like this:
Point localPoint = fileMenuItem.DropDown.PointToClient(hlpevent.MousePos);
if(exitMenuItem == fileMenuItem.DropDown.GetItemAt(localPoint)) Does this help?
|
|
|
|
|
Wow. Thanks. I updated my code. I tried it but I got an undefined for the control.
Programmer
Glenn Earl Graham
Austin, TX
|
|
|
|
|
I'm not sure I understand. You got null back for the control returned?
|
|
|
|
|
Wouldn't MouseEnter / MouseLeave or whatever work?
|
|
|
|
|
If you wanted an event for every menuitem. I was hoping there was a cleaner way.
PIEBALDconsult wrote: Wouldn't MouseEnter / MouseLeave or whatever work?
Programmer
Glenn Earl Graham
Austin, TX
|
|
|
|
|
Hi,
I have not used it myself, but the way I understand MSDN on Control.HelpRequested event
you should add an event to every Control for which you want to provide help; then in
the HelpRequested event handler the sender parameter points to the Control that currently
needs to show help.
|
|
|
|
|
For the menu dropdown items there is no event for the helpprovider. There is for the file menu itself but it does not tell you which menu item you are currently looking at.
Luc Pattyn wrote: I have not used it myself, but the way I understand MSDN on Control.HelpRequested event
you should add an event to every Control for which you want to provide help; then in
the HelpRequested event handler the sender parameter points to the Control that currently
needs to show help.
Programmer
Glenn Earl Graham
Austin, TX
|
|
|
|
|
OK, I see the problem now: MenuItem is not a Control. However MainMenu and ContextMenu
are, so you could enumerate their menu items recursively to find the one that is currently
selected (MenuItem.Selected property). Not sure what will happen when you move the
mouse up or down, selecting another menu item.
|
|
|
|
|
Thank You very much. It works like a champ! Here is my final code (c++/CLI).
for each ( ToolStripMenuItem ^tmpMS in this->menuMainForm->Items )
{
for each ( ToolStripItem ^tmpCntl in tmpMS->DropDownItems )
{
if (tmpCntl)
{
if ( tmpCntl->Selected )
String ^tmpCntlName = tmpCntl->Name;
OpenHelpForMenuItem(tmpCntlName);
}
}
}
Programmer
Glenn Earl Graham
Austin, TX
|
|
|
|
|
hi.. how do i browse a word document and get the data inside to my richtextBox ?
|
|
|
|
|
You'll either need to use the Word interop COM object (requires Word to be installed on the machine running your software), or use a 3rd party tool that parses Word documents to get the text data out or coverts it to RTF.
|
|
|
|
|
if i want to use the Word interop COM object .. what should i do.. thanks
|
|
|
|
|
|
Hi all,
How could i trim the calender control (Cla.selecteddate) to only dat
when i click the control it comes with time .But i only want the date only.Like '2008-01-10' not like 2008-01001 12:00:00Am'
Thank you!
|
|
|
|
|
Use the ToShortDateString or ToLongDateString methods.
Standards are great! Everybody should have one!
|
|
|
|
|
I don't know what a Cla.selecteddate is, but if you're use a DateTimePicker you can set a CustomFormat.
|
|
|
|