Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > Pro VB.NET 2002/2003
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 3rd, 2004, 11:08 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
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
 
Old February 14th, 2006, 10:26 PM
Registered User
 
Join Date: Feb 2006
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.


 
Old June 2nd, 2006, 12:27 PM
78 78 is offline
Registered User
 
Join Date: Jun 2006
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.

 
Old November 15th, 2006, 06:29 PM
Registered User
 
Join Date: Nov 2006
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
 
Old March 13th, 2007, 12:16 PM
Registered User
 
Join Date: Mar 2007
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";
            }
        }
    }
}

 
Old March 13th, 2007, 12:21 PM
Registered User
 
Join Date: Mar 2007
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

 
Old July 12th, 2007, 10:19 AM
Registered User
 
Join Date: Jul 2007
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";
            }
        }
    }
}

 
Old July 17th, 2008, 09:57 AM
Registered User
 
Join Date: Jul 2008
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


 
Old July 17th, 2008, 10:24 AM
Registered User
 
Join Date: Jul 2008
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



 
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/





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 03:40 AM
how to change all control color ashish2001mca .NET Framework 2.0 1 February 23rd, 2005 12:47 AM
change background color of toolbar control myth12345 VB How-To 1 January 6th, 2005 12:25 AM
Color change possability? rolandatem VB How-To 2 November 19th, 2004 03:52 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.