Click here to Skip to main content
15,894,106 members
Home / Discussions / Windows Forms
   

Windows Forms

 
QuestionDatagridview example Pin
mistryshailesh22-Jul-09 16:52
mistryshailesh22-Jul-09 16:52 
AnswerRe: Datagridview example Pin
Eddy Vluggen22-Jul-09 22:04
professionalEddy Vluggen22-Jul-09 22:04 
NewsWindows 7 RTM Dates Announced; Free Resources to Help Get Ready Pin
brucedkyle22-Jul-09 13:09
brucedkyle22-Jul-09 13:09 
Questionchanging the background color of single word in textbox Pin
Member 232448322-Jul-09 11:46
Member 232448322-Jul-09 11:46 
AnswerRe: changing the background color of single word in textbox Pin
Luc Pattyn22-Jul-09 12:04
sitebuilderLuc Pattyn22-Jul-09 12:04 
GeneralRe: changing the background color of single word in textbox [modified] Pin
Member 232448322-Jul-09 12:13
Member 232448322-Jul-09 12:13 
GeneralRe: changing the background color of single word in textbox Pin
Luc Pattyn22-Jul-09 12:25
sitebuilderLuc Pattyn22-Jul-09 12:25 
GeneralRe: changing the background color of single word in textbox Pin
Member 232448322-Jul-09 13:33
Member 232448322-Jul-09 13:33 
I am able to accomplish this with following code. But the problem i am facing is, when i select the text the drawn string is vanishing and the string is back to unformatted with no background color. Any ideas whats going on?

<br />
 protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)<br />
        {<br />
            <br />
            Rectangle rect = new Rectangle();<br />
            rect.Y = this.Bounds.Y + 2;<br />
            rect.Height = this.Bounds.Height - 5;<br />
<br />
            string str = this.Text;<br />
            int index = this.Text.IndexOf("test1");<br />
<br />
<br />
            string sBefore = str.Substring(0, index);<br />
            string sWord = str.Substring(index, 5);<br />
<br />
            Graphics g = this.CreateGraphics();<br />
<br />
            Size s1 = TextRenderer.MeasureText(e.Graphics, sBefore, this.Font, this.Bounds.Size);<br />
            Size s2 = TextRenderer.MeasureText(e.Graphics, sWord, this.Font, this.Bounds.Size);<br />
<br />
<br />
            //'adjust the widths to make the highlite more accurate<br />
            if (s1.Width > 5)<br />
            {<br />
                rect.X = this.Bounds.X + s1.Width - 5;<br />
                rect.Width = s2.Width - 6;<br />
            }<br />
            else<br />
            {<br />
                rect.X = this.Bounds.X + 2;<br />
                rect.Width = s2.Width - 6;<br />
            }<br />
<br />
<br />
            //'use darker highlight when the row is selected<br />
            SolidBrush hl_brush;<br />
            hl_brush = new SolidBrush(Color.Yellow);<br />
            //End If<br />
<br />
            //'paint the background behind the search word<br />
            e.Graphics.FillRectangle(hl_brush, rect);<br />
            e.Graphics.DrawString(this.Text, this.Font, new SolidBrush(Color.Black), (Width - Size.Width) / 2, 0);<br />
            //this.Text = string.Empty;<br />
            //TextRenderer.DrawText(e.Graphics, this.Text, Font, Bounds, ForeColor, BackColor,<br />
            //      TextFormatFlags.HorizontalCenter |<br />
            //      TextFormatFlags.VerticalCenter |<br />
            //      TextFormatFlags.TextBoxControl);<br />
<br />
            hl_brush.Dispose();<br />
            base.OnPaint(e);<br />
        }<br />



Thanks.
GeneralRe: changing the background color of single word in textbox Pin
Luc Pattyn22-Jul-09 13:41
sitebuilderLuc Pattyn22-Jul-09 13:41 
GeneralRe: changing the background color of single word in textbox Pin
Member 232448322-Jul-09 15:22
Member 232448322-Jul-09 15:22 
GeneralRe: changing the background color of single word in textbox Pin
Luc Pattyn22-Jul-09 15:39
sitebuilderLuc Pattyn22-Jul-09 15:39 
AnswerRe: changing the background color of single word in textbox Pin
Adrian Cole5-Aug-09 12:05
Adrian Cole5-Aug-09 12:05 
QuestionHow to restrict the string lenght in propertygrid item in vb.net [modified] Pin
dilipmca0421-Jul-09 21:07
dilipmca0421-Jul-09 21:07 
QuestionCustom UserControl and scrollbars Pin
invictus321-Jul-09 10:49
invictus321-Jul-09 10:49 
AnswerRe: Custom UserControl and scrollbars Pin
Eddy Vluggen22-Jul-09 21:58
professionalEddy Vluggen22-Jul-09 21:58 
Questioncode for retreving user DSN's Pin
chennu Jul2920-Jul-09 20:50
chennu Jul2920-Jul-09 20:50 
Questiontype initializer for 'Gdip' threw an exception Pin
baldree20-Jul-09 13:46
baldree20-Jul-09 13:46 
Questionhow return Dataadapter and dataset from function in class file for multiple use Pin
hemrk20-Jul-09 6:08
hemrk20-Jul-09 6:08 
AnswerRe: how return Dataadapter and dataset from function in class file for multiple use Pin
DoctorMick20-Jul-09 6:16
DoctorMick20-Jul-09 6:16 
GeneralHelp on how to build sms web portal for my church for e-evengenlism Pin
abbah19-Jul-09 22:51
abbah19-Jul-09 22:51 
GeneralRe: Help on how to build sms web portal for my church for e-evengenlism Pin
Dave Kreskowiak21-Jul-09 4:25
mveDave Kreskowiak21-Jul-09 4:25 
JokeRe: Help on how to build sms web portal for my church for e-evengenlism Pin
Paul Conrad26-Jul-09 11:11
professionalPaul Conrad26-Jul-09 11:11 
Question"extended version" of post to Lounge : Applause ! : shareware version of AlphaForm now on CP, and free [modified] Pin
BillWoodruff19-Jul-09 15:04
professionalBillWoodruff19-Jul-09 15:04 
Questionhow to programatically raise keyPress event of a user control? Pin
imak19-Jul-09 9:54
imak19-Jul-09 9:54 
AnswerRe: how to programatically raise keyPress event of a user control? Pin
Luc Pattyn19-Jul-09 10:33
sitebuilderLuc Pattyn19-Jul-09 10:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.