473,788 Members | 2,820 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1825
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.Componen tModel.IContain er components;

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

MessageFilter msgFilter = new MessageFilter() ;
public Form1(int a)
{
//
// Required for Windows Form Designer support
//
InitializeCompo nent();
Application.Add MessageFilter(m sgFilter);

}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Disp ose();
}
}
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 InitializeCompo nent()
{
this.button1 = new System.Windows. Forms.Button();
this.textBox1 = new System.Windows. Forms.TextBox() ;
this.checkBox1 = new System.Windows. Forms.CheckBox( );
this.SuspendLay out();
//
// button1
//
this.button1.Lo cation = new System.Drawing. Point(120, 320);
this.button1.Na me = "button1";
this.button1.Ta bIndex = 0;
this.button1.Te xt = "button1";
this.button1.Cl ick += new System.EventHan dler(this.butto n1_Click);
//
// textBox1
//
this.textBox1.L ocation = new System.Drawing. Point(56, 48);
this.textBox1.N ame = "textBox1";
this.textBox1.T abIndex = 1;
this.textBox1.T ext = "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.AutoScaleB aseSize = new System.Drawing. Size(5, 13);
this.CausesVali dation = false;
this.ClientSize = new System.Drawing. Size(352, 374);
this.Controls.A dd(this.checkBo x1);
this.Controls.A dd(this.textBox 1);
this.Controls.A dd(this.button1 );
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayo ut(false);

}
#endregion

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

public bool PreFilterMessag e(ref Message m)
{
if(m.Msg >= WM_KEYFIRST && m.Msg <= WM_KEYLAST)
{
return this.BlockKeybo ard;
}

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

private void button1_Click(o bject sender, System.EventArg s e)
{

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

}

}
"Vish" <Vi**@discussio ns.microsoft.co m> wrote in message
news:93******** *************** ***********@mic rosoft.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.Componen tModel.IContain er components;

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

MessageFilter msgFilter = new MessageFilter() ;
public Form1(int a)
{
//
// Required for Windows Form Designer support
//
InitializeCompo nent();
Application.Add MessageFilter(m sgFilter);

}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Disp ose();
}
}
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 InitializeCompo nent()
{
this.button1 = new System.Windows. Forms.Button();
this.textBox1 = new System.Windows. Forms.TextBox() ;
this.checkBox1 = new System.Windows. Forms.CheckBox( );
this.SuspendLay out();
//
// button1
//
this.button1.Lo cation = new System.Drawing. Point(120, 320);
this.button1.Na me = "button1";
this.button1.Ta bIndex = 0;
this.button1.Te xt = "button1";
this.button1.Cl ick += new System.EventHan dler(this.butto n1_Click);
//
// textBox1
//
this.textBox1.L ocation = new System.Drawing. Point(56, 48);
this.textBox1.N ame = "textBox1";
this.textBox1.T abIndex = 1;
this.textBox1.T ext = "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.AutoScaleB aseSize = new System.Drawing. Size(5, 13);
this.CausesVali dation = false;
this.ClientSize = new System.Drawing. Size(352, 374);
this.Controls.A dd(this.checkBo x1);
this.Controls.A dd(this.textBox 1);
this.Controls.A dd(this.button1 );
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayo ut(false);

}
#endregion

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

public bool PreFilterMessag e(ref Message m)
{
if(m.Msg >= WM_KEYFIRST && m.Msg <= WM_KEYLAST)
{
return this.BlockKeybo ard;
}

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

private void button1_Click(o bject sender, System.EventArg s e)
{

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

}

}
"Vish" <Vi**@discussio ns.microsoft.co m> wrote in message
news:93******** *************** ***********@mic rosoft.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
1660
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 hopefully point out in the standard where this mode of operation is specified. Here is the test code: std::stringstream a; float f; int i;
2
2509
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
3358
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 Cisco Router and i selected Sync reading since i have an expected datapattern when this app runs. However i thought that the read method where supposed to wait util the
3
6090
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 port in a syncronious state so that it wont return before it has finished? And no - I can't use the work around to smaple until I got all 100 bytes read because I use the timeout option in my app. Thanks
17
5414
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 think it is mostly not going to happen for ++ operation since it is not something like read a value and wait sometime then write back in multiple threading environment, BTW, is this understanding right?).
5
3306
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 namespace std; int read(string filename, int last_pos) {
0
3869
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 string. write method should take a string. seek should take a number and return nuthing. use three member variables a buffer itself as a string, read_position, write_position. use >>, << methods. I have tried this code but i need full...
3
2839
by: gert | last post by:
what is the difference between iter(lambda:f.read(8192), ') and iter(f.read(8192),'') ?
4
2808
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 following data.bin (3 Data appended to 2 Data): 2, data0, data1, 3, data0, data1, data2
1
3929
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 of. f.open(filename,ios::in | ios::out | ios::binary | ios::trunc) The program flow is 1) write some data 2) read the data
0
9498
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10366
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9967
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4070
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3674
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.