|
ok, im stuck in a very stupid situation.
I have a checkbox, i change it's value through user input AND through runtime code.
Problem:
When i change the value by code, it fires the checkedchanged event, which, in my opinion, is pretty damn stupid. I know it works for most people, and it may look normal to most people, but for me is very stupid. Example: u have a checkbox that, when pressed, if a certain condition is met, calls a function and changes another checkbox state (or even himself), WITHOUT triggering the changedevent. Y? Cause i want to separate user input from runtime code changes and this stupid control (and others,from what i've seen) mix it all up!
Do you know any property to avoid this or another event, to avoid this stupid behavior?
Thanks in Advance!
|
|
|
|
|
I checked in both .Net Framework 1.1 and 2.0, and the programmically changing the checkbox value does not fire the CheckedChanged event. The following example demonstrates this. If you toggle the checkbox, the textbox goes from String.Empty to 0 and, subsequently each time the checkbox gets toggled, the number in the textbox gets incremented. However, when you click on the button, the checkbox gets toggled but the textbox does not display the above described behavior.
Framework 2.0
Default.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></div>
<div style="margin-top: 10pt;">
<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="True" OnCheckedChanged="CheckBox1_CheckedChanged" />
</div>
<div style="margin-top: 10pt;"><asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /></div>
</form>
</body>
</html>
Default.aspx.cs:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
int value = 0;
if (Int32.TryParse(TextBox1.Text, out value))
{
TextBox1.Text = (++value).ToString();
}
else
{
TextBox1.Text = value.ToString();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
CheckBox1.Checked = (CheckBox1.Checked) ? false : true;
}
}
|
|
|
|
|
Same for Windows Forms:
Windows Form Designer:
namespace CheckWin
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.checkBox1 = new System.Windows.Forms.CheckBox();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(12, 23);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(100, 20);
this.textBox1.TabIndex = 0;
//
// checkBox1
//
this.checkBox1.AutoSize = true;
this.checkBox1.Location = new System.Drawing.Point(143, 25);
this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(80, 17);
this.checkBox1.TabIndex = 1;
this.checkBox1.Text = "checkBox1";
this.checkBox1.UseVisualStyleBackColor = true;
this.checkBox1.Click += new System.EventHandler(this.checkBox1_Click);
//
// button1
//
this.button1.Location = new System.Drawing.Point(22, 81);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 2;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(292, 171);
this.Controls.Add(this.button1);
this.Controls.Add(this.checkBox1);
this.Controls.Add(this.textBox1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.CheckBox checkBox1;
private System.Windows.Forms.Button button1;
}
}
Windows Form Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace CheckWin
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
checkBox1.Checked = (checkBox1.Checked) ? false : true;
}
private void checkBox1_Click(object sender, EventArgs e)
{
int value = 0;
if (Int32.TryParse(textBox1.Text, out value))
{
textBox1.Text = (++value).ToString();
}
else
{
textBox1.Text = value.ToString();
}
}
}
}
|
|
|
|
|
George's replies line up with what I've found, but if it's still messing up for you, you could always set a variable with the click function and with the code, and check that variable on check changed before you run anything else.
if(clicked == false)
//click toggled
else
//code toggled
|
|
|
|
|
Meh!
Sorry for the inconveniance. I was handling the CheckedChanged Event, not the click event. It's my 1st .Net project, usually i do c++ stuff, and as i am still a bit suspicious about .net, i thought it was another weird VB-like think they had.:->
Thank you all for the quick response.
|
|
|
|
|
What he is referring to is a boolean flag variable:
Pseudo Code:
class
{
protected:
void CheckedChanged()
{
if (flag)
{
//Process whatever
}
}
void RunTimeCode()
{
flag = false;
// Change Checkbox via code
flag = true;
}
private:
bool flag = true;
}
-- modified at 20:55 Friday 17th February, 2006
|
|
|
|
|
show about "AddMessageFilter" of Aplictaion class
maybe is parallel function in Control class
|
|
|
|
|
Ok, I am using a global hook, and I am wondering how I can keep the keys from sending to the active program.
I searched around the net and CodeProject and I just can't figure it out. I'm not terribly familiar with WindowsAPI stuff.
Thanks in advance.
-- modified at 19:33 Friday 17th February, 2006
|
|
|
|
|
You just figured it out? So, what is your problem?
-- modified at 19:23 Friday 17th February, 2006
|
|
|
|
|
Just *can't* figure out.
Why is it that we always leave out the mosti mportant words? haha.
|
|
|
|
|
This might help: http://msdn2.microsoft.com/en-us/library/system.windows.forms.application.addmessagefilter.aspx[^]
<br />
static void Main() <br />
{<br />
Application.AddMessageFilter(new TestMessageFilter());<br />
Application.Run(new Form1());<br />
}<br />
<br />
public class TestMessageFilter : IMessageFilter <br />
{<br />
public bool PreFilterMessage(ref Message m) <br />
{<br />
const int WM_KEYDOWN= 0x0100;<br />
if (m.Msg==WM_KEYDOWN) <br />
{<br />
MessageBox.Show("KeyDown hitted"); <br />
}<br />
<br />
return false;<br />
}<br />
}<br />
<br />
-- modified at 19:54 Friday 17th February, 2006
|
|
|
|
|
What type of hook are you using? A really global hook that captures all keyboard events from the whole system, or a hook that only applies to one application? Maybe you can show us a bit of code?
"..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.."
-- Mark McCormick || Fold With Us! || Pensieve || VG.Net ||
|
|
|
|
|
It is a global keyboard hook. I am using the Kennedy.ManagedHooks DLL from this site. I enable it with a hotkey, and disable it the same way.
public Form1()<br />
{<br />
Form1.RegisterHotKey(this.Handle,this.GetType().GetHashCode(), 8, (int)'P');<br />
InitializeComponent();<br />
keyboardHook = new Kennedy.ManagedHooks.KeyboardTracking();<br />
keyboardHook.KeyboardEvent += new Kennedy.ManagedHooks.KeyboardTracking.KeyboardEventHandler(keyboardHook_KeyboardEventExt);<br />
<br />
}<br />
protected override void WndProc(ref Message m)<br />
{<br />
if (m.Msg == 0x0312)<br />
if (keyboardHook.IsHooked)<br />
{<br />
keyboardHook.UninstallHook();<br />
input = false;<br />
textBox4.Text = "";<br />
}<br />
else<br />
{<br />
textBox4.Text = "";<br />
keyboardHook.InstallHook();<br />
input = true;<br />
}<br />
base.WndProc(ref m);<br />
}<br />
private void keyboardHook_KeyboardEventExt(Kennedy.ManagedHooks.KeyboardEvents kEvent, Keys key)<br />
{<br />
bool shi;<br />
if(keyboardHook.ShiftPressed == true)<br />
shi = true;<br />
else<br />
shi = false;<br />
if(kEvent == KeyboardEvents.KeyDown){<br />
string msg;<br />
if(shi == true)<br />
msg = key.ToString();<br />
else<br />
msg = key.ToString().ToLower();<br />
textBox4.Text += msg;<br />
}<br />
}<br />
I think that covers all the relevant code from my end of the application. If there are any questions about what anything does more specifically, I can answer those. The Hotkey works fine, and I am planning to add the message filter or whatever when it hotkeys in and remove it when they hotkey out of the hook, obviously. Thanks for the help thus far.
|
|
|
|
|
Well, in the "real" global hook implementation I did in C++, years ago, the solution is simple. You just don't pass the keystroke message up the hook chain. But I don't see a way to do that, or more to the point NOT do that, using this library. At least it's not obvious in the code you've posted.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Also, I am using WH_KEYBOARD_LL to hook, if that helps out more.
|
|
|
|
|
Ok, I am just going to use blockinput() I think. It blocks the mouse too, but oh well.
|
|
|
|
|
All you need to do to eat the key message is NOT call the CallNextHookEx function in your KeyboardProc handler. It's that simple...
LowLevelKeyboardProc Function[^]
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-- modified at 9:33 Saturday 18th February, 2006
|
|
|
|
|
Thanks! I'll go mess around with my hooking code.
|
|
|
|
|
hi all
can anyone tell me how to import a flash file into a .NET winForm ? please suggest appropriate class libraries.
thanks
|
|
|
|
|
Hi!
I want to compose a large UserControl of many sub-controls. These children may also be composed of many other controls.
All the childs and grandchilds are not supposed to handle Click events themselves. How can the event be propagated to the parent without subscribing to the Click events of all children and grandchildren and grandgrandchildren an so on?
Thanks,
Eric
|
|
|
|
|
Please excuse my ignorance on this whole .NET thing but I guess everyone in this field eventually gets around to it...
From what I understand, Windows Forms are the next generation of MFC designed for use in a .NET, managed code environment. Is that correct?
Does this mean I have to write managed code to use 3rd party api's that are built on Windows Forms (i.e., Dundas Chart, Gauge and Diagram products)?
Or, can I continue to write unmanaged code and still utilize Windows Forms based api's in C++ code? In other words, can I use the Dundas products in unmanaged C++ code?
Thanks in advance!
Bob
|
|
|
|
|
If the component is a managed code class library, then no you can't use it directly from unmanaged code. You'd have to go through a COM to get at the managed classes, if those classes are exposed to COM.
Exposing .NET Framework Components to COM[^]
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I was wondering how much work is involved on the developer's side to convert an application to calling WinHelp to HTML (or Web) Help.
Are there some standard steps a programmer should go through to ensure this transition is clean and works properly? This is for a .NET environment.
If you've been through this, any information would be helpful.
Thank you,
ellenu
|
|
|
|
|
need help where to download a free full version of FlexCell 2.0 .net framework..... really appreciated if you can provide a link where i can download it for free...
tnx tnx tnx and more power...............
|
|
|
|
|