|
No way. Use RTB.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
RTB is heavy for my scenario, i was thinking whether can be done by overriding OnPaint/WndProc?
Thanks
modified on Wednesday, July 22, 2009 6:19 PM
|
|
|
|
|
You can paint anything you want on any Control you choose, so the Form itself, or a Panel, would be fine. Why still use a Label if it doesn't do what you want? You still need to tell it somehow which parts need which colors.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
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 />
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 />
SolidBrush hl_brush;<br />
hl_brush = new SolidBrush(Color.Yellow);<br />
<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 />
<br />
hl_brush.Dispose();<br />
base.OnPaint(e);<br />
}<br />
Thanks.
|
|
|
|
|
What do you think base.OnPaint(e); would do for a Label?
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
text should be selectable.
|
|
|
|
|
I don't think OnPaint() contributes to selection.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
You can't do this in the TextBox control. However, you could create your own control that derives from TextBox and override the Paint method to do whatever you wish. Of course you'd have to come up with some way of specifying which word(s) have different colour backgrounds. Seems like a lot of work when RichTextBox already does this.
while (e) { Coyote(); }
|
|
|
|
|
in propertygrid having name property .. How to restrict user only type in name property maximum 50 characters.. how to do this..always user is enter only 50 character ..after enter 51 character don't allow to typing..
This is the code i am adding Item in propertygrid..
<Category("Misc")> <Browsable(True)> <DisplayName("(Name)")> <Description("Indicates the name of the control to identify on the page")> _
Public Property Name() As String
Get
Return _Name
End Get
Set(ByVal value As String)
_Name = value
End Set
End Property
Thanks..
modified on Wednesday, July 22, 2009 6:46 AM
|
|
|
|
|
Hi
I have written a small UserControl that, at the moment, only overrides the OnPaint event without anything else. However, the content I am drawing in the control is sometimes larger than the display-area itself, so I want to implement scrollbar-functionality that allows the user to scroll if the content does not fit the screen.
I have googled a bit for this topic, but can not find any good information, and my book only tells me how to draw UserControls, not how to implement scrollbars. Any ideas where I can get started with this?
Appreciate any help
|
|
|
|
|
Hello.
1) Put your UserControl in a new Panel .
2) Set the AutoScroll property of the Panel to "true".
Enjoy
|
|
|
|
|
i need code for retreving user DSN's which are created in system
|
|
|
|
|
C# desktop application will not start when using non-administrative user. Suspect permissions issue, but cannot pinpoint. Please help. Appears to be related to .jpg background image on main form. Here is the start of the error received (cannot reproduce in IDE, so cannot cut and paste):
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.TypeInitializationException: The type initializer for 'Gdip' threw an exception. ---> System.DllNotFoundException: Dll was not found.
at System.Drawing.SafeNativeMethods.Gdip.GdiplusStartup(IntPtr& token, StartupInput& input, StartupOutput& output)
at System.Drawing.SafeNativeMethods.Gdip.Initialize()
at System.Drawing.SafeNativeMethods.Gdip..cctor()
--- End of inner exception stack trace ---
<snip>
at applicationName.Properties.Resources.get_background()
at applicationName.frmMain.InitializeComponenet()
at applicationname.frmMain..ctor()
at applicationName.Program.Main()
Have resinstalled .Net framework 3.5 and set full folder and file permissions available to all users on the .net framework folders as well as to our application folder, to no avail.
Any suggestions would be greatly appreciated.
|
|
|
|
|
i have created function in class file.
Public Shared Function dsCntrctET() As DataSet
Dim sqlCntrct As String = "Select * from CNTRCT_ET where CNTRCT_ID=" & CISCNO
Dim cmdCISContract As New OracleCommand
Dim daCISCntrct As New OracleDataAdapter
Dim dsCISCntrct As New DataSet
Dim cmdCISBuilder As New OracleCommandBuilder
Try
With cmdCISContract
.Transaction = myTransCIS
.CommandText = sqlCntrct
.Connection = cnCIS
End With
daCISCntrct = New OracleDataAdapter(cmdCISContract)
daCISCntrct.FillSchema(dsCISCntrct, SchemaType.Source)
cmdCISBuilder = New OracleCommandBuilder(daCISCntrct)
With daCISCntrct
.TableMappings.Add("Table", "CNTRCT_ET")
.Fill(dsCISCntrct)
.SelectCommand = cmdCISContract
.InsertCommand = cmdCISBuilder.GetInsertCommand
.UpdateCommand = cmdCISBuilder.GetUpdateCommand
.DeleteCommand = cmdCISBuilder.GetDeleteCommand
End With
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Return (dsCISCntrct)
End Function
it returns dataset that i can use for getting value from table.
but while saving data, i have to use dataadapter for da.update(ds,"table") and ds.acceptchanges.
this i have to use in multiple forms as this data comes from 3rd party so i dont want to write this in every form . so i thought how to return data adapter and dataset from the same function. as i wanted to use daCISCntrct and dsCISCntrct.
|
|
|
|
|
Don't cross post in multiple forums.
Have a look at out parameters.
|
|
|
|
|
I need help on how to build an sms web portal for e-evegenlism, for my church,please i need the source code.
Thanks
|
|
|
|
|
abbah wrote: please i need the source code.
Ummm...it doesn't work that way. This is part where YOU write the code. We'll help when you run into a specific problem. But, noone is going to write your code for you.
|
|
|
|
|
Dave Kreskowiak wrote: This is part where YOU write the code
True, I could tease him by saying I've got full source code for such project but it is so buried in a stack of CDs in my garage that it'll take me about 2 years to find it
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
< this contains the original Lounge post and content of material I deliberately left out of the Lounge post : feeling it was more appropriate here >
Hi,
I'm delighted to see that Jeff Anderson his taken latest version of AlphaForm[^], which was being sold as shareware, and now made it available to us, under the Code Project license, free !
I've created a "stress test" example of using Jeff's code that will move quite smoothly with virtually zero flicker, at run-time on an older system with no graphics card (i.e., using motherboard/CPU integration of all rendering) : PIV single core, 2.93 mhz, XP Pro SP 3, VS Studio 2010 beta, FrameWork 4.0, which I consider excellent since the load on the CPU for calculating the non-rectangular clipping regions must be high.
This example uses a .png bitmap saved in PhotoShop CS 4 as 24-bit .png with transparency, size 800x600, which includes one main content area, and two other content areas which are disconnected from the main content area (i.e., the form has non-overlapping areas of transparency : contains "holes") : inside this form there are two torodial areas cut-out from the main content area through which the underlying WinForm can be shown, and on which controls to be used at runtime can be placed. The source graphics (the complete images, source and the image mask files) I have optimized down to under 500k total using very valuable hints and tips found here[^]. I suspect further optimization is possible (particularly on the mask image, and I am experimenting with that trying to find the optimum level of reduction possible).
You can see the source image I'm using here[^], and the clipping mask image here[^].
These images are based on an excerpt from an image[^] in the public domain shown on Wikipedia, they are not original. The image is from a detail of a bronze frieze dating back probably a least 2000-2200 years ago, at Sarnath in India, showing the teacher born as Siddhartha of the Sakyas, and later known as Gautama the Buddha, giving what has become known as the "turning of the wheel" teaching that is believed, by Buddhists, to have "set in motion" (in a non-singular way [from the Theravadan Buddhist point of view]) the insights and practices that have led to what we now know as Buddhism. I was in Sarnath in October of 1975, and had a wonderful time there, even saw a live deer in the park !
If I reach the point where I feel I have enough mastery of Jeff's code that I can modify a few things, and have something substantial to say about using that modified version, or feel I have something useful to add about how to optimize use of it (or its source graphics files), I'll do a brief write-up, and post a link to it here (the WinForms forum) : hope you might do likewise if you use it and modify it.
So, thanks Jeff !
best, Bill
"Many : not conversant with mathematical studies, imagine that because it [the Analytical Engine] is to give results in numerical notation, its processes must consequently be arithmetical, numerical, rather than algebraical and analytical. This is an error. The engine can arrange and combine numerical quantities as if they were letters or any other general symbols; and it fact it might bring out its results in algebraical notation, were provisions made accordingly." Ada, Countess Lovelace, 1844
modified on Sunday, July 19, 2009 9:17 PM
|
|
|
|
|
I have a user control that contains a textbox control. I am getting some data from serial port. Anytime i get this data I need to raise keypress event of the user control that should internally riase keypress event of text box. I am a newbie to winforms and will very much appreciate if someone can walk me through steps on how to do this.
|
|
|
|
|
Hi,
two comments:
1.
are you sure you want KeyPress events? if all you want is append some text to a TextBox, why not use the TextBox.AppendText() method?
2.
if you use SerialPort.DataReceived event, you must be aware that event does not fire on the main/GUI thread; hence you cannot directly touch GUI Controls, you will need Control.InvokeRequired and Control.Invoke. If those are unfamiliar, search for InvokeRequired.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Thanks for your response. My real problem is much more complicated so I am just used a simple example. All I basically need is to know how can I programatically raise keypress event of a text box that is contained within a user control. Any code example will be highly appreciated
|
|
|
|
|
Any ideas about this guys? I really need it very urgently.
TIA
|
|
|
|
|
Hi everyone,
I am new to code project , sorry if i place the question in wrong area. I am struck by a problem while using threads. In my windows project I have MDI form and shows different forms in the MDI form.In one form i am sending mails. i am sending the mails in a separate process using threads to enable the user to do anything in the application while sending the mails.one progress bar will appear in the mdi form status strip, when mail is sending.
When user clicks the Send button in the form i make it disable until the mail is sent.Before calling thread i make it disable and after completion of thread's work i make it enable, it works fine. but my problem is, When user opens this form and send mails, if he visits another form and again comes to this form i am checking in the form load whether thread is going on, by check whether progress bar is visible in the mdi form , if it is visible i make the send button disable. I need the send button enable after thread completion, i make it. but it is not working. the send button is still disabled.I don't know why it is happening. if user remains in the same form it is working fine. if he visits another form it is not working. I am using thread invoke method for using the controls. but still the problem is there.
Please any one help me
Thanks in advance.
Rajesh.
|
|
|
|
|
Hi,
threads can't access Controls directly, only the main thread can. You need one of two things:
1. use the Control.InvokeRequired/Control.Invoke pattern (search for InvokeRequired in CP articles)
2. or use a BackgroundWorker instead of a Thread; that one has InvokeRequired built-in into its ReportProgress and WorkCompleted events.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|