如题

解决方案 »

  1.   

    用css可以  类似这个  那个图片就是椭圆的
    .main1field
    {
    font-family: "Arial" , "Helvetica" , "sans-serif";
    font-size: 14px;
    color: #0660B0;
    background-image: url(../images/main_1_fieldbg.gif);
    background-repeat: no-repeat;
    border: none;
    height: 21px;
    width: 217px;
    padding-top: 3px;
    padding-right: 8px;
    padding-bottom: 3px;
    padding-left: 8px;
    background-attachment: fixed;
    }
      

  2.   

    winform or web form?
      

  3.   

    http://www.codeproject.com/useritems/RoundedCornerTextbox.asp
      

  4.   

    自己画, 或者直接使用WPF
      

  5.   

    有c#的吗?找了好久也没有找到这样的控件,vb的我看的不是很懂
      

  6.   

    前面看到一个高手写的:
    namespace UnderLineBox
    {
        public class UnderLineBox : TextBox
        {
            private bool m_underLine;        public bool UnderLine
            {
                get { return m_underLine; }
                set
                {
                    if (this.m_underLine != value)
                    {
                        if (value)
                        {
                            this.BorderStyle = BorderStyle.None;
                        }
                        m_underLine = value;
                    }
                }
            }
            protected override void WndProc(ref Message m)
            {
                base.WndProc(ref m);
                if (m.Msg == 0xf || m.Msg == 0x14 || m.Msg == 0x85)
                {
                    if (this.BorderStyle == BorderStyle.None)
                    {
                        if (m_underLine)
                        {
                            using (Graphics g = Graphics.FromHwnd(this.Handle))
                            {
                                g.DrawLine(SystemPens.ControlText, 0, this.Height - 1, this.Width - 1, this.Height - 1);//这里写你要绘制的形状。
                            }
                        }
                    }
                }
            }
        }}
      

  7.   

    如楼上所示
    自定义一个继承TextBox的自定义控件,重绘TextBox
      

  8.   

    那样做只是在textBox里画了一个形状,我是希望textBox的外形都变了,TextBox不支持OnPaint事件
      

  9.   

    using System;
    using System.ComponentModel;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Text;
    using System.Windows.Forms;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Runtime.InteropServices;namespace testApplication1
    {
        public partial class RounderTextBox : TextBox
        {
            #region Declare        private States state = States.Normal;
            private Pen borderPen;
            private Brush textBrush;
            private Rectangle mainRect;
            private PointF txtLoc;        private enum States
            {
                Normal,
                Focused,
                Disabled
            }        #endregion        #region DLL Import
    [DllImport("user32.dll")]
    private static extern IntPtr GetWindowDC(IntPtr hwnd);
            [DllImport("user32.dll")]
            private static extern int ReleaseDC(IntPtr hwnd, IntPtr hDC);
            #endregion        public RounderTextBox()
            {
                
            }        protected override void WndProc(ref Message m)
            {
                switch(m.Msg)
                {
                    case 15:
                        Rectangle rect = new Rectangle(0, 0, base.Width, base.Height);
                        IntPtr hDC = GetWindowDC(this.Handle);
                        Graphics g = Graphics.FromHdc(hDC);
                        if (this.Enabled)
                        {
                            g.Clear(Color.White);
                        }
                        else
                        {
                            g.Clear(Color.FromName("control"));
                        }                    DrawBorder(g);
                        DrawText(g);
                        ReleaseDC(this.Handle, hDC);
                        g.Dispose();
                        break;
                    case 7:
                    case 8:
                        UpdateState();
                        break;
                }            base.WndProc(ref m);
            }        #region Draw Method
            private void DrawBorder(Graphics g)
            {
                mainRect = new Rectangle(0, 0, this.Width - 1, this.Height - 1);
                switch (state)
                {
                    case States.Focused:
                        borderPen = new Pen(Color.Blue);
                        break;
                    case States.Disabled:
                        borderPen = new Pen(Color.DarkGray);
                        break;
                    case States.Normal:
                        borderPen = new Pen(Color.DimGray);
                        break;
                }            TekenRondeRechthoek(g, borderPen, mainRect, 3);
            }        private void TekenRondeRechthoek(Graphics g, Pen pen, Rectangle rectangle, 
                float radius)
            {
                float size = radius * 2;
                GraphicsPath gp = new GraphicsPath();
                gp.AddArc(rectangle.X, rectangle.Y, size, size, 180, 90);
                gp.AddArc((rectangle.X + (rectangle.Width - size)), rectangle.Y, size, size, 270, 90);
                gp.AddArc((rectangle.X + (rectangle.Width - size)),
                    (rectangle.Y + (rectangle.Height - size)), size, size, 0, 90);
                gp.AddArc(rectangle.X, (rectangle.Y + (rectangle.Height - size)), size, size, 90, 90);
                gp.CloseFigure();
                g.DrawPath(pen, gp);
                gp.Dispose();
            }        private void DrawText(Graphics g)
            {
                string text = "";
                switch (state)
                {
                    case States.Normal:
                    case States.Focused:
                        textBrush = new SolidBrush(this.ForeColor);
                        break;
                    case States.Disabled:
                        textBrush = new SolidBrush(Color.DarkGray);
                        break;
                }
                if (g.MeasureString(this.Text, this.Font).Width > this.Width - 30)
                {
                    int i = -1;
                    while (g.MeasureString(text, this.Font).Width > this.Width - 30)
                    {
                        i++;
                        text += this.Text.Substring(i, 1);
                    }
                }
                else
                {
                    text = this.Text;
                }
                float temp;
                if (this.RightToLeft == RightToLeft.No)
                {
                    temp = 1;
                }
                else
                {
                    temp = this.Width - g.MeasureString(text, this.Font).Width;
                }
                txtLoc = new PointF(temp, 4);
                g.DrawString(text, this.Font, textBrush, txtLoc);
            }        #endregion        private void UpdateState()
            {
                States temp = state;
                if (this.Enabled)
                {
                    if (ClientRectangle.Contains(PointToClient(Control.MousePosition)))
                    {
                        this.state = States.Focused;
                    }
                    else if (this.Focused)
                    {
                        this.state = States.Focused;
                    }
                    else
                    {
                        this.state = States.Normal;
                    }
                }
                else
                {
                    this.state = States.Disabled;
                }
                if ((state & temp) != state)
                {
                    this.Invalidate();
                }            
            }
        }
    }大致的翻译了一下那个VB.NET的Source
    你自己在根据需要改改就可以了
    主要的思路就是继承一个TextBox
    然后监视他的WndProc消息
    在WM_Paint消息的时候重绘这个TextBox
    如果是Button或者窗口的话就容易的多
    直接利用GraphicsPath修改Region就可以了
      

  10.   

    直接在在WM_Paint消息的时候,把DrawBorder换成如下Source
    GraphicsPath p = new GraphicsPath();
                int width = this.ClientSize.Width;
                int height = this.ClientSize.Height;
                p.AddClosedCurve(new Point[]{new Point(width/2, height/10), 
                  new Point(width,0), new Point(width, height/3),
                  new Point(width-width/3, height),
                  new Point(width/7, height-height/8)});
                this.Region = new Region(p);
                this.Invalidate();
    这个改变的很清楚
    当然你要调整相应的DrawText代码