Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > Pro VB.NET 2002/2003
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Pro VB.NET 2002/2003 For advanced Visual Basic coders working .NET version 2002/2003. Beginning-level questions will be redirected to other forums, including Beginning VB.NET.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB.NET 2002/2003 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #11 (permalink)  
Old December 3rd, 2004, 10:08 AM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,190
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

esche:

locked porperty on .net just lock the control to the form, making you not enable to move it...

the locked from vb6 was change to readonly...

HTH

Gonzalo
Reply With Quote
  #12 (permalink)  
Old February 14th, 2006, 09:26 PM
Registered User
 
Join Date: Feb 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry to bring this thread back up and it came out from my google search to set textbox as readonly but no grey out the textbox.

I found a simple solution:
1) Set the textbox readonly property to false
2) on event keypress, I'll handle this event
Code:
Private Sub MyReadOnlyTextBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyReadOnlyTextBox.KeyPress
    e.Handled = True
End Sub
This will not allow user to enter or delete anything in the textbox and you can set whatever color you like, as well as allowing user to select text and set focus to the textbox.


Reply With Quote
  #13 (permalink)  
Old June 2nd, 2006, 12:27 PM
78 78 is offline
Registered User
 
Join Date: Jun 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Probably old news but for the googlers...
setting Enabled=No, Locked=Yes, Tab Stop=No might be another option.

Reply With Quote
  #14 (permalink)  
Old November 15th, 2006, 05:29 PM
Registered User
 
Join Date: Nov 2006
Location: new york, new york, USA.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to cammarata123
Default

Why wouldnt you just use a label

Nick Cammarata
Reply With Quote
  #15 (permalink)  
Old March 13th, 2007, 12:16 PM
Registered User
 
Join Date: Mar 2007
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You might want to try something like this:

I have created myTextBox with an override for the paint. If the control is disabled - its one color and enabled - another. You can check on the box to see if it is disabled by the mouseover override. The project consists of 2 controls tbHowdy and btnEnable. In the Form1.Designer I replaced the default Initialize component with:

this.tbHowdy = new disable_textbox.Form1.myTextBox();

Hope this helps

namespace disable_textbox
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnEnable_Click(object sender, EventArgs e)
        {
            if (tbHowdy.Enabled)
            {
                tbHowdy.Enabled = false;
                btnEnable.Text = "Enable";
            }
            else
            {
                tbHowdy.Enabled = true;
                btnEnable.Text = "Disable";
            }
        }
        public class myTextBox : TextBox
        {
            public myTextBox()
            {
                SetStyle(ControlStyles.UserPaint, true);
            }

            // override on paint
            protected override void OnPaint(PaintEventArgs e)
            {
                if (this.Enabled)
                {
                    SolidBrush drawBrush = new SolidBrush(Color.Red); //Use the ForeColor property
                    // Draw string to screen.
                    e.Graphics.DrawString(Text, Font, drawBrush, 0f, 0f); //Use the Font property
                }
                else
                {
                    SolidBrush drawBrush = new SolidBrush(Color.Blue); //Use the ForeColor property
                    // Draw string to screen.
                    e.Graphics.DrawString(Text, Font, drawBrush, 0f, 0f); //Use the Font property
                }
            }
            protected override void OnMouseHover(EventArgs e)
            {
                base.OnMouseHover(e);
                base.Text = "blah";
            }
        }
    }
}

Reply With Quote
  #16 (permalink)  
Old March 13th, 2007, 12:21 PM
Registered User
 
Join Date: Mar 2007
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry - I see this is a VB forum - but I am sure that it is similar in VB

Reply With Quote
  #17 (permalink)  
Old July 12th, 2007, 10:19 AM
Registered User
 
Join Date: Jul 2007
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

When I refresh the control, it goes to enabled again and when highlighted the font changes, disappears, etc... how do I return the entire textbox as normal again.

Quote:
quote:Originally posted by zamnut6
 You might want to try something like this:

I have created myTextBox with an override for the paint. If the control is disabled - its one color and enabled - another. You can check on the box to see if it is disabled by the mouseover override. The project consists of 2 controls tbHowdy and btnEnable. In the Form1.Designer I replaced the default Initialize component with:

this.tbHowdy = new disable_textbox.Form1.myTextBox();

Hope this helps

namespace disable_textbox
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnEnable_Click(object sender, EventArgs e)
        {
            if (tbHowdy.Enabled)
            {
                tbHowdy.Enabled = false;
                btnEnable.Text = "Enable";
            }
            else
            {
                tbHowdy.Enabled = true;
                btnEnable.Text = "Disable";
            }
        }
        public class myTextBox : TextBox
        {
            public myTextBox()
            {
                SetStyle(ControlStyles.UserPaint, true);
            }

            // override on paint
            protected override void OnPaint(PaintEventArgs e)
            {
                if (this.Enabled)
                {
                    SolidBrush drawBrush = new SolidBrush(Color.Red); //Use the ForeColor property
                    // Draw string to screen.
                    e.Graphics.DrawString(Text, Font, drawBrush, 0f, 0f); //Use the Font property
                }
                else
                {
                    SolidBrush drawBrush = new SolidBrush(Color.Blue); //Use the ForeColor property
                    // Draw string to screen.
                    e.Graphics.DrawString(Text, Font, drawBrush, 0f, 0f); //Use the Font property
                }
            }
            protected override void OnMouseHover(EventArgs e)
            {
                base.OnMouseHover(e);
                base.Text = "blah";
            }
        }
    }
}

Reply With Quote
  #18 (permalink)  
Old July 17th, 2008, 09:57 AM
Registered User
 
Join Date: Jul 2008
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by cammarata123
 Why wouldnt you just use a label


My reasoning would be I want the text to be allowed to be copied to the clipboard. Eating all keypress events, doesn't give me that either.

But allowing Ctrl-C through gives me what I want.


        If Not (Control.ModifierKeys = Keys.Control AndAlso e.KeyChar = "c"c) Then
            e.Handled = True
        End If


Reply With Quote
  #19 (permalink)  
Old July 17th, 2008, 10:24 AM
Registered User
 
Join Date: Jul 2008
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry, that code didn't actually work, but this seems to do the trick.

        ' don't handle Ctrl-C
        If Not (e.KeyChar = Chr(3)) Then
            e.Handled = True
        End If



Reply With Quote
  #20 (permalink)  
Old April 19th, 2009, 02:36 AM
Registered User
 
Join Date: Apr 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default this may offer some help

though I'm too struggling with this, there is some thing that is possible

http://codeforfuture.com/2008/12/24/...r-radiobutton/
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
re: color change jack_in_black ASP.NET 2.0 Professional 0 July 11th, 2006 07:24 AM
TD Color Change echovue Javascript How-To 1 March 3rd, 2006 02:40 AM
how to change all control color ashish2001mca .NET Framework 2.0 1 February 22nd, 2005 11:47 PM
change background color of toolbar control myth12345 VB How-To 1 January 5th, 2005 11:25 PM
Color change possability? rolandatem VB How-To 2 November 19th, 2004 02:52 PM



All times are GMT -4. The time now is 03:08 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.