|
I agree. But, I didn't mean it as a cheap shot, the situation DOES warrant it, and I hope it helps.
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 )
|
|
|
|
|
Hi,
I wrote a piece of code to monitor keyword activities (just for fun and testing this api func) I want to know what is wrong? sometime I get this error:
{"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."}
Stack trace:
" at System.Windows.Forms.UnsafeNativeMethods.PeekMessage(MSG& msg, HandleRef hwnd, Int32 msgMin, Int32 msgMax, Int32 remove)\r\n at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)\r\n at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)\r\n at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)\r\n at System.Windows.Forms.Application.Run()\r\n at hook.Program.Main() in C:\\Documents and Settings\\Nazila\\My Documents\\Visual Studio 2005\\Projects\\hook\\hook\\Program.cs:line 19"
my code is :
public class KeyPosition<br />
{<br />
static public Int16 WM_KEYDOWN = 0x0100;<br />
static public Int16 WM_KEYUP = 0x0101;<br />
static public Int16 WM_SYSKEYDOWN = 0x0104;<br />
static public Int16 WM_SYSKEYUP = 0x0105;<br />
}<br />
<br />
delegate int HookProc(int code, IntPtr wParam, ref keyboardHookStruct lParam);<br />
<br />
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]<br />
static extern IntPtr SetWindowsHookEx(HookType hook, HookProc callback, IntPtr hMod, uint dwThreadId);<br />
<br />
[DllImport("user32.dll", CharSet = CharSet.Auto,CallingConvention = CallingConvention.StdCall)]<br />
public static extern bool UnhookWindowsHookEx(int idHook);<br />
<br />
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]<br />
static extern int CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, ref keyboardHookStruct lParam);<br />
<br />
[DllImport("kernel32.dll")]<br />
static extern IntPtr LoadLibrary(string lpFileName);<br />
<br />
public enum HookType : int<br />
{<br />
WH_JOURNALRECORD = 0,<br />
WH_JOURNALPLAYBACK = 1,<br />
WH_KEYBOARD = 2,<br />
WH_GETMESSAGE = 3,<br />
WH_CALLWNDPROC = 4,<br />
WH_CBT = 5,<br />
WH_SYSMSGFILTER = 6,<br />
WH_MOUSE = 7,<br />
WH_HARDWARE = 8,<br />
WH_DEBUG = 9,<br />
WH_SHELL = 10,<br />
WH_FOREGROUNDIDLE = 11,<br />
WH_CALLWNDPROCRET = 12,<br />
WH_KEYBOARD_LL = 13,<br />
WH_MOUSE_LL = 14<br />
}<br />
<br />
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto,Pack=1)]<br />
public struct keyboardHookStruct<br />
{<br />
public int vkCode;<br />
public int scanCode;<br />
public int flags;<br />
public int time;<br />
public int dwExtraInfo;<br />
}<br />
<br />
static IntPtr hooked = IntPtr.Zero;<br />
private void Form1_Load(object sender, EventArgs e)<br />
{<br />
this.Hide();<br />
IntPtr hInstance = LoadLibrary("User32");<br />
hooked = SetWindowsHookEx(HookType.WH_KEYBOARD_LL,Form1.Hook, hInstance, 0);<br />
<br />
}<br />
static string hookedstr;<br />
static string hookedDownStr;<br />
<br />
public static int Hook(int code, IntPtr wParam, ref keyboardHookStruct lParam)<br />
{<br />
<br />
if (code < 0)<br />
{<br />
return CallNextHookEx(hooked, code, wParam, ref lParam);<br />
}<br />
if ((int)wParam == KeyPosition.WM_KEYDOWN)<br />
{<br />
hookedstr += "[D]";<br />
hookedDownStr += ((Keys)lParam.vkCode).ToString() + " ";<br />
}<br />
hookedstr += ((Keys)lParam.vkCode).ToString() + " ";<br />
return CallNextHookEx(hooked, code, wParam, ref lParam);<br />
}<br />
<br />
return 0;<br />
}
|
|
|
|
|
I have a datagridview to display one datasource. I catch record to modify and then display on screen
|
|
|
|
|
So
do u want to bind to gridview?
set the datsource and datamember to gridview.
that's all
thanks
|
|
|
|
|
Please read this[^].
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 my application I am able to load plugins, i.e. use reflection look in an assembly for classes implementing a given interface and instantiate them.
I would like these plugins to run with restricted right.
Like they are not able to access the file system, etc....
How could I do that?
Also, from some prelimiary reading it seems I will have to run thess plugin in different AppDomain, but these plugin need to create some WPF.Controls I'm adding to my main form's visual tree hierachy.
Is it possible to do that? I mean add in the UITree a WPF.Control which is from a different AppDomain?
(I foresee a dispatcher problem)
Any tip? (or maybe I don't need to run my plugin in a different AppDomain after all?)
|
|
|
|
|
I have used crystal reports in C# .net in my application
when I run my application on my client PC where Visual Studio 2005 IDE is not installed, the forms having crystal report do not display.
The .net framework 2.0 has already been installed on the coimputers but I was wondering if there is any other also required to display crystal reports.
Sadaf
|
|
|
|
|
Ok can can
Please check ur client pc for MS report viewer is installed?
thanks
|
|
|
|
|
How come this doesn't work when you click the button?
foreach (Control txt in this.Controls)
{
if (txt.GetType() == typeof(System.Windows.Forms.TextBox))
{
txt.Text = "";
}
}
I had another one that using a for statement instead of foreach and it won't work either.. here it is:
for (int i = 0; i < this.Controls.Count; i++)
{
if (this.Controls[i] is TextBox)
{
this.Controls[i].Text = "";
}
}
|
|
|
|
|
Try casting the control to a textbox then reference its properties.
Just because we can; does not mean we should.
|
|
|
|
|
Uhm what do you mean by that?
|
|
|
|
|
Here's an example. You need to "cast" it to the type of control you expect it to be and not the control object it self. Simply comparing its types wont give you access to the, in this case a TextBox, properties like .Text and so forth.
foreach (Control txt in this.Controls)
{
if (txt.GetType() == typeof(System.Windows.Forms.TextBox))
{
TextBox txtbx = (TextBox)txt;
txtbx.Text = "";
}
}
Just because we can; does not mean we should.
|
|
|
|
|
Ok I see, but it still isn't working.. its weird because I have this:
for (int i = 0; i < this.Controls.Count; i++)
{
if (this.Controls[i] is TextBox)
{
this.Controls[i].Text = "";
}
}
under a listbox selection change committed and it works every time!
|
|
|
|
|
Jacob Dixon wrote: for (int i = 0; i < this.Controls.Count; i++) { if (this.Controls[i] is TextBox) { this.Controls[i].Text = ""; } }
Instead of 'is', use 'as'.
TextBox tb = Controls[i] as TextBox;
if (tb != null)
{
// whatever
}
If the property you use exists on the Control class, then your code will work, if you try to use properties that are specific to the class you failed to cast to, it will not.
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 )
|
|
|
|
|
So if your talking about this it still doesn't work:
private void button10_Click(object sender, EventArgs e)
{
for (int i = 0; i < this.Controls.Count; i++)
{
TextBox tb = Controls[i] as TextBox;
if (tb != null)
{
tb.Text = "";
}
}
Phone2Listbox.Items.Clear();
phoneListbox.Items.Clear();
AuthPhone1Listbox.Items.Clear();
AuthPhone2Listbox.Items.Clear();
AuthPhone3Listbox.Items.Clear();
MedAllergiesListbox.Items.Clear();
MedPhoneListbox.Items.Clear();
EmergPhoneListbox.Items.Clear();
PaidToDateListbox.Items.Clear();
richTextBox1.Clear();
othercomments.Clear();
}
Is that what you were talking about?
|
|
|
|
|
Yes, if that doesn't work, then this code just plain is not running, or something else is strange on your form.
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 )
|
|
|
|
|
Both examples work under a button click event.
<br />
foreach (Control txt in this.Controls)<br />
{<br />
if (txt.GetType() == typeof(System.Windows.Forms.TextBox))<br />
{<br />
TextBox txtbx = (TextBox)txt;<br />
txtbx.Text = "";<br />
}<br />
} <br />
<br />
<br />
for (int i = 0; i < this.Controls.Count; i++)<br />
{<br />
if (this.Controls[i] is TextBox)<br />
{<br />
this.Controls[i].Text = "";<br />
}<br />
}
Difference between the two is that the first refers to a Control object. So you need to cast it to the TextBox control to gain access to the TextBox property?. Otherwise your setting the text of the control. Check it out in the debugger! In the second you reference the actual object and this exposes the objects, in this case a TextBox, .Text property.
Hope this helps.
Just because we can; does not mean we should.
|
|
|
|
|
Also, 'it won't work' is not really a question. What does it do ? Does it compile ? What happens when you step through it in the debugger ? I suspect your real problem is not casting, as Control has a Text property, but you've not really done enough work to tell us what is going on, or to try and work out what's really happening.
My best guess is that this code is not running at all.
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 )
|
|
|
|
|
I am using the same thing on the listbox selection committed and it works..
I set some break points to see if it is doing anything.. I am not getting any errors at all.
I have about twenty textboxes and I see that it is clearing one text box. But it is not clearing any of the other ones.
|
|
|
|
|
actually it is clearing that one textbox and every item in a ListBox???
|
|
|
|
|
Hi
Yes u way is rite,but chaneg ur code like this
foreach (Control txt in this.Controls)
{
if (txt as TextBox)
{
txt.Text = string.Empty;
this.Refresh();
}
}
I think this should be work for u.
thanks
|
|
|
|
|
That is doing the same thing... it clears a listbox, and a richtextbox but none of the regular text boxes
That one Textbox that it was clearing with the other codes I changed to a Label, because that is the only one that I wanted not to clear lol
So that is clearing all the items in a listbox, and the richtextbox, but not any of the other ones. I don't know whats going on.. I don't know what to see you.. I posted the exact code for the button click event
|
|
|
|
|
Hi
Please give a clear picture ,wat are u trying?
once time say listbox, after say textbox?
So, So tell me, wat u r trying?
thanks
|
|
|
|
|
Ok.. I have a button that is suppose to clear EVERY textbox on my form. That is what I am trying to accomplish! The buttons code is this:
This is EXACTLY what I have:
private void button10_Click(object sender, EventArgs e)
{
foreach (Control txt in this.Controls)
{
if (txt is TextBox)
{
txt.Text = string.Empty;
this.Refresh();
}
}
Phone2Listbox.Items.Clear();
phoneListbox.Items.Clear();
AuthPhone1Listbox.Items.Clear();
AuthPhone2Listbox.Items.Clear();
AuthPhone3Listbox.Items.Clear();
MedAllergiesListbox.Items.Clear();
MedPhoneListbox.Items.Clear();
EmergPhoneListbox.Items.Clear();
PaidToDateListbox.Items.Clear();
richTextBox1.Clear();
othercomments.Clear();
}
I am sorry that I said it was clearing a listbox, that is the code I have above that is clearing the textbox, and richtextbox. I'm tired, so sorry I said that.
The point is, is that it is not clearing the textboxes.. When I load my form I just type random crap in the text boxes and click my button (Clear All) and it doesn't clear the textboxes..
By the way I can't do:
if (txt as TextBox)
It has to be:
if (txt is TextBox)
The reason is, is because when you use the txt AS textbox it throws an exeception:
" Cannot implicity convert type 'System.Windows.Forms.Textbox' to 'bool' "
|
|
|
|
|
OK cool
can can
i'm directly typed that code in that post,and this is web applications?
|
|
|
|
|