|
Excluing native interop I don't think that there is a way.
Are you unable or just don't want to inherit from the TextBox? If you're unable, can you give us some more information on your situation?
Jared Parsons
jaredp@beanseed.org
http://spaces.msn.com/members/jaredp/
|
|
|
|
|
The ideea is to make a class that recives\intercept key messages from a TextBox, process them and if necesary block the respective key from being processed by the TextBox.
The ideea of inheriting is not so great because this class should work with all kind of other control (richTextBox, comboBox, etc...)
Thank you!
protected internal static readonly ... and I wish the list could continue ...
|
|
|
|
|
Yeah - subscribe to the KeyPress event. This event passes a KeyPressEventArgs which has a boolean Handled field. Setting this to true stops the message being passed on to the text box handler, so you can do your processing in this event.
Regards,
Rob Philpott.
|
|
|
|
|
Thanks for your answer, but I allready know this. The problem is that in a TextBox if you press for exemple the VK_LEFT the cursor moves to left if is a character there.
I want to intercept this type of key before processing and decide if it mut be processed or not. (KeyPress event work's only for char key's if I am not mistaking)
protected internal static readonly ... and I wish the list could continue ...
|
|
|
|
|
Ah, ok.
Well, you can intercept virtual keys using the KeyDown event which is fired prior to the KeyPress event.
eg. To disable the left cursor key:
<br />
private void textBox1_KeyDown(object sender, KeyEventArgs e)<br />
{<br />
if (e.KeyCode == Keys.Left)<br />
{<br />
e.Handled = true;<br />
}<br />
}<br />
You may still need to worry about mouse selection depending upon what you are doing...
Regards,
Rob Philpott.
|
|
|
|
|
Hi all!
I got a Windows Forms application where an event is fired from a secondary thread. When this event is fired, I call
this.BeginInvoke(new MethodInvoker(someMenuItem.PerformClick)); to simulate a menu item click.
This works fine, but when the event handler for someMenuItem pops up a modal dialog, this dialog appears more than once if the event re-fires before the first dialog is closed.
So I tried encapsulating someMenuItem 's event handler code inside a lock(this) {} and now only a single modal dialog is shown at most.
So far, so good.
But if the event re-fires now, all these events are suspended as long as the lock() statement is active and executed in row afterwards.
Is there a way to change the behaviour so that the events are discarded instead of being stored?
Thanks in advance for any ideas,
mav
|
|
|
|
|
|
Jared, thanks for your comment!
Of course, you're right. That way I can block the second thread until the first call to the event handler is finished.
The dialog can still pop up twice in a row (when I click the menu item in the main app and afterwards the other thread fires the event), but I think I'll use this approach nevertheless.
Or do you have any further suggestions on how to really discard every other call?
Thanks,
mav
|
|
|
|
|
The only way I can think of is having a volatile bool variable that is set before Invoke and is reset after it. That way, you can simply return if the flag is set.
class XYZ
{
volatile bool isMessageBoxVisible = false;
void Func()
{
lock(this)
{
if (isMessageBoxVisible) return;
isMessageBoxVisible = true;
}
this.Invoke(...);
lock(this) { isMessageBoxVisible = false; }
}
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Thanks!
That could be a way, but then it gets quite messy, because I allow the user to configure which menu item or toolbar button is pressed when a certain button on the external input device is clicked.
So I'd have to create a variable for each and every menu item/toolbar button...
I was looking for a behaviour like what you get when you use the mouse to click a menu item/tbb. A modal dialog can pop up, but then the UI of the main window is not accessable any more and thus the same menu item/tbb can't be pushed more than once. And the additional clicks aren't queued but discarded.
Something like
if (mainForm.IsIdle)
this.Invoke(... But just as I write this I got another idea:
I usually set the form's Cursor to Cursors.WaitCursor at the beginning of my menu/toolbar event handlers and reset it to Default in a finally block.
This information can be used to decide whether the main form is busy (executing an event handler) or not. I think I'll try it like this:
if (mainForm.Cursor == Cursors.Default)
this.Invoke(...
Thank you all for your help!
mav
|
|
|
|
|
i wrote a sales report, which works fine with my application if i include start date and end date in the database, {gndsale.dob} in {date.startdate} to {date.enddate}.
but if i change the report to pass Parameter Fields, {gndsale.dob} in {?Start Date} to {?End Date}
when i load the report first time it's okay i can see the correct parameters on the Page header and in Details, but if i load report 2nd time with different parameters , the page header is updated but the details not, some how i need to refresh crystalReportViewer1 after i pass parameters. ???
check this code
ReportDocument1.Load(RptPath.ToString());
crystalReportViewer1.RefreshReport();
crystalReportViewer1.ReportSource = reportDocument1;
paramFields = new ParameterFields ();
ParameterField crParamFld = new ParameterField();
ParameterDiscreteValue CrparamValue = new ParameterDiscreteValue();
paramFields = crystalReportViewer1.ParameterFieldInfo;
crParamFld = paramFields[0];
CrparamValue.Value = PassDT_Start;
crParamFld.CurrentValues.Add(CrparamValue);
ParameterField crParamFld_2 = new ParameterField();
ParameterDiscreteValue CrparamValue_2 = new ParameterDiscreteValue();
crParamFld_2 = paramFields[1];
CrparamValue_2.Value = PassDT_End;
crParamFld_2.CurrentValues.Add(CrparamValue_2);
crystalReportViewer1.ParameterFieldInfo = paramFields;
crystalReportViewer1.ReportSource = reportDocument1;
Or this code
reportDocument1.SetParameterValue("Start Date",PassDT_Start );
reportDocument1.SetParameterValue("End Date",PassDT_End );
crystalReportViewer1.RefreshReport();
crystalReportViewer1.ReportSource = reportDocument1;
|
|
|
|
|
Hello,
I’m programming an MDI application. My application contains a sizable child form and a fixed dialog form. The problem is that when I maximize the sizable form, the fixed dialog form is maximised too. I don’t know how to keep the fixed dialog form in its normal state while the sizable child form is maximized. Has any one a solution? Thanks.
|
|
|
|
|
Is the dialog form an MDI Child form? If so, you can't seperate the two. If one MDI Child is maximized, they're all maximized. There is no way to stop that from happening. The solution is to make the dialog form a normal form, not an MDI Child.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
The Error:
Could not find file "\\myserver\share$\myfile.txt".
The Code:
File.Copy(@"\\myserver\share$\myfile.txt",@"c:\myfile.txt"), true);
The file is there. The premissions on the share$ is set to everyone. I can navigate to the file using the above quoted string. What am I missing?
|
|
|
|
|
|
Hi!
I guess the problem lies in the share itself.
If you enter "\\myserver\share$" in the address bar of a windows explorer, do you get a dialog asking for a user name and password?
If you can see the file in your explorer, does the program still throw the exception afterwards?
Or is the code executed from within a windows service process running under LocalSystem account?
mav
|
|
|
|
|
thank you for responding...
no.. no dialog box appears. Any lowly person in the company and open this share no problem.
And the code is being executed by ASPNET account
|
|
|
|
|
i think i've boiled down the issue. ASPNET service account is a local service account to my machine. I'm trying to copy a file from a domain server. The premissions on the server is set to everyone, but that means everyone in the Domain, not local mcahin accounts. Now I need to figure out how to pass premissions with my file.copy... any clues?
|
|
|
|
|
You don't.
You can create a domain account, restrict it's log to certain machines!, that the ASP.NET server can run under. It doesn't have to run under a local machine account!
Then you can give that domain account appropriate rights to the machines and folders required to run your code and do file copies.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Maybe the parameter are incorrect you can try with the ip:
File.Copy(@"\###.###.###.###\directory\file.txt",@"c:\file.txt",true);
I can use the instruction like my example and work well.
|
|
|
|
|
Hi,
I will retrive a lot of data from database into a datatable and display these records into user interface as a datagrid or datarepeater. The problem is the data has to be retrived again from database every time when I want to narrow down the search result or even just go to different pages of the datarepeater.
Is there anyway to save the table records so that I can use the data dirctly instead of connect to sql server everytime. I dont want to save it into a session, coz it could be expired anytime.
Thanks.
|
|
|
|
|
Hi there,
There are some options come to mind, IMO:
- using cache mechanism
- using export the datatable to temporary xml file
<< >>
|
|
|
|
|
Create a DataView from the DataTable, and display that. apply filters, page selection logic to the datatable to create the dataview.
Absolute faith corrupts as absolutely as absolute power
Eric Hoffer
All that is necessary for the triumph of evil is that good men do nothing.
Edmund Burke
|
|
|
|
|
I thinking caching is the best alternative to ur problem. U can then also set dependency with ur database. By that way if in the meanwhile database had been modified, u can know it as ur cache will get empty....
Regards,
Sandeep
+919891027854
|
|
|
|
|
I have a DataSet that contains a table "results" which is popuated with data from a database.
I need to know the number of rows in the "results" table. Is there a simple way to grab this information? A property or some such? Thanks.
|
|
|
|