473,387 Members | 1,590 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Read-Only and edit states for a from

Hi,

I amplanning on having a rea-only and edit states for my form. But it do not
want my form and its controls to look different or disabled. I am planning on
having a edit button that brings the form from read-only to a edit state. Is
there any easy or built-in way of doing this in .NET?

My preimary purpose for doing it because the combobox controls on my form
take a while to load all their data from the database. Since the user uses
the form only to view information most of the time, i dont want the form to
load the data eveytime. The data will only be loaded when the user clicks on
the edit button.

Thank you,
Vish
Mar 14 '06 #1
2 1801
Vish,

It looks like you don't want to disable the form because this will change
the outlook of all controls.

I don't know it there is no better solution, but the one that comes to my
mind is to use messge filter and filter out keyboard and mouse events before
they reach the child controls.

Here is some sample code that blocks all keyboard messages, thus prevents
user of typing in the edit boxes.

Ofcourse this is only an idea. a start for really workable solution. For
example you want to block some messages send to some controls on the form,
but not to all controls; you wanna block mouse messeges to check boxes, but
not to the button that switches the readonly mode on and off.

/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.CheckBox checkBox1;
private System.ComponentModel.IContainer components;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
}

MessageFilter msgFilter = new MessageFilter();
public Form1(int a)
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
Application.AddMessageFilter(msgFilter);

}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (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.button1 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.checkBox1 = new System.Windows.Forms.CheckBox();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(120, 320);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(56, 48);
this.textBox1.Name = "textBox1";
this.textBox1.TabIndex = 1;
this.textBox1.Text = "textBox1";
//
// checkBox1
//
this.checkBox1.Location = new System.Drawing.Point(56, 88);
this.checkBox1.Name = "checkBox1";
this.checkBox1.TabIndex = 2;
this.checkBox1.Text = "checkBox1";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.CausesValidation = false;
this.ClientSize = new System.Drawing.Size(352, 374);
this.Controls.Add(this.checkBox1);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}
#endregion

class MessageFilter:IMessageFilter
{
private const int WM_KEYFIRST = 0x0100;
private const int WM_KEYLAST = 0x0109;
public bool BlockKeyboard = true;

public bool PreFilterMessage(ref Message m)
{
if(m.Msg >= WM_KEYFIRST && m.Msg <= WM_KEYLAST)
{
return this.BlockKeyboard;
}

return false;
}
}
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1(1));
}

private void button1_Click(object sender, System.EventArgs e)
{

this.msgFilter.BlockKeyboard = !this.msgFilter.BlockKeyboard;

}

}
"Vish" <Vi**@discussions.microsoft.com> wrote in message
news:93**********************************@microsof t.com...
Hi,

I amplanning on having a rea-only and edit states for my form. But it do
not
want my form and its controls to look different or disabled. I am planning
on
having a edit button that brings the form from read-only to a edit state.
Is
there any easy or built-in way of doing this in .NET?

My preimary purpose for doing it because the combobox controls on my form
take a while to load all their data from the database. Since the user uses
the form only to view information most of the time, i dont want the form
to
load the data eveytime. The data will only be loaded when the user clicks
on
the edit button.

Thank you,
Vish

Mar 14 '06 #2
Hi,

I appreciate your suggestion. But my form is in a DLL that is called by
other applications. So i do not have access to the Application class. Also
this form is only a small part of a bigger application and i do not want the
messages to other windows being blocked. Any ideas?

Thank You,
Vish

"Stoitcho Goutsev (100)" wrote:
Vish,

It looks like you don't want to disable the form because this will change
the outlook of all controls.

I don't know it there is no better solution, but the one that comes to my
mind is to use messge filter and filter out keyboard and mouse events before
they reach the child controls.

Here is some sample code that blocks all keyboard messages, thus prevents
user of typing in the edit boxes.

Ofcourse this is only an idea. a start for really workable solution. For
example you want to block some messages send to some controls on the form,
but not to all controls; you wanna block mouse messeges to check boxes, but
not to the button that switches the readonly mode on and off.

/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.CheckBox checkBox1;
private System.ComponentModel.IContainer components;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
}

MessageFilter msgFilter = new MessageFilter();
public Form1(int a)
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
Application.AddMessageFilter(msgFilter);

}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (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.button1 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.checkBox1 = new System.Windows.Forms.CheckBox();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(120, 320);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(56, 48);
this.textBox1.Name = "textBox1";
this.textBox1.TabIndex = 1;
this.textBox1.Text = "textBox1";
//
// checkBox1
//
this.checkBox1.Location = new System.Drawing.Point(56, 88);
this.checkBox1.Name = "checkBox1";
this.checkBox1.TabIndex = 2;
this.checkBox1.Text = "checkBox1";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.CausesValidation = false;
this.ClientSize = new System.Drawing.Size(352, 374);
this.Controls.Add(this.checkBox1);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}
#endregion

class MessageFilter:IMessageFilter
{
private const int WM_KEYFIRST = 0x0100;
private const int WM_KEYLAST = 0x0109;
public bool BlockKeyboard = true;

public bool PreFilterMessage(ref Message m)
{
if(m.Msg >= WM_KEYFIRST && m.Msg <= WM_KEYLAST)
{
return this.BlockKeyboard;
}

return false;
}
}
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1(1));
}

private void button1_Click(object sender, System.EventArgs e)
{

this.msgFilter.BlockKeyboard = !this.msgFilter.BlockKeyboard;

}

}
"Vish" <Vi**@discussions.microsoft.com> wrote in message
news:93**********************************@microsof t.com...
Hi,

I amplanning on having a rea-only and edit states for my form. But it do
not
want my form and its controls to look different or disabled. I am planning
on
having a edit button that brings the form from read-only to a edit state.
Is
there any easy or built-in way of doing this in .NET?

My preimary purpose for doing it because the combobox controls on my form
take a while to load all their data from the database. Since the user uses
the form only to view information most of the time, i dont want the form
to
load the data eveytime. The data will only be loaded when the user clicks
on
the edit button.

Thank you,
Vish


Mar 14 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Garrett Kajmowicz | last post by:
I have two implementations of stringstream and they both handle interleaved reads and writes differently. I was hoping that you might be able to shed some light as to the "correct" operation, and...
2
by: Andrea Bauer | last post by:
Hallo, wie kann ich so eine Datei unter .Net schreiben C++ oder C#. Bitte mit Funktionsaufrufen. Vielen Dank. Grüße Andrea <Product> <ProgramNumber>2</ProgramNumber>
4
by: Kai Thorsrud | last post by:
Hi, Thanks a lot for the short path solution to the app i'm working on by including a Perl script ( App i'm converting from perl to .Net) for the part i can't do yet. I'm communicating with a...
3
by: Ole | last post by:
I got a problem with serial port read which I use like this: sp.Read (byteBuffer, 0, 100); but the problem is that it returns before it has read the 100 bytes - is there a way to set up the...
17
by: Ryan Liu | last post by:
Hi, If I have many threads write to a variable(e.g. var++) and another thread read it on an interval base. For those writing thread, I know I need lock, or its value could be lower ( even I...
5
by: lovecreatesbea... | last post by:
The condition at line 31 is added to check if the program finished to read the whole file. Is it needed and correct? Thank you. #include <fstream> #include <iostream> #include <string> using...
0
by: martinmercy2001 | last post by:
Could any body help me with creating a ring buffer class using a string. use memory circular buffer not an IO buffer. just read, write and seek method. Read method should take anumber and return the...
3
by: gert | last post by:
what is the difference between iter(lambda:f.read(8192), ') and iter(f.read(8192),'') ?
4
by: zl2k | last post by:
hi, there I have a appendable binary file of complex data structure named data.bin created by myself. It is written in the following format: number of Data, Data array Suppose I have...
1
by: Sachin Garg | last post by:
I have a program which opens a fstream in binary input+output mode, creating the file if it doesn't exists. But writing doesn't works after reading, it must be something obvious that I am not aware...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.