Click here to Skip to main content
15,902,939 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
0 down vote favorite


I want to make textbox text as Hyperlink. Suppose if i type www.google.com as tetxbox text,when i click on the text ,it show open the link in a browser..

I could not get any idea to implement this...can u suggest me any idea...i tried the two ways.

way1:
HTML
<TextBox Grid.Row="4" Name="txtWebPage" VerticalAlignment="Top" TextDecorations="UnderLine" TextChanged="txtWebPage_TextChanged" Foreground="Blue">
                                </TextBox>


way2:

<pre lang="HTML">
<RichTextBox Grid.Row="4" Name="rtxtWeb" BorderBrush="Gray" BorderThickness="1" VerticalAlignment="Top" Height="20" IsDocumentEnabled="True" Foreground="Blue" LostFocus="rtxtWeb_LostFocus">
                                    <FlowDocument>
                                        <Paragraph>
                                            <Hyperlink NavigateUri=""/>
                                        </Paragraph>
                                    </FlowDocument>
                                </RichTextBox>

I couldnt get how can i bind the RichTextBox text to Hyperlink uri!!! There is no click event for richtextbox...any suggestion please...
Posted
Comments
[no name] 16-Jul-13 21:47pm    
Why are you not just using a HyperLink? http://msdn.microsoft.com/en-us/library/system.windows.documents.hyperlink.aspx
keerth516 16-Jul-13 22:01pm    
I want textbox text as a hyperlink,when click on the textbox text ,it should open in the browser.
Sergey Alexandrovich Kryukov 16-Jul-13 22:53pm    
Why?! Use HyperLink or at least TextBox...
Anyway, what's the problem? You can always handle events and get the TextBox content...
—SA
keerth516 16-Jul-13 23:16pm    
OnMouseDoubleClick event is there for Textbox...not Click event...On MousedoubleClick is working fine...how can i achieve for single click?
Sergey Alexandrovich Kryukov 17-Jul-13 0:25am    
That's why I did not recommend TextBox. How one could edit using the mouse if each click is handled in... who knows how?!
Anyway, the problem is resolved via events MouseDown, PreviewMouseDown, MouseUp or PreviewMouseUp, isn't it obvious? But why? You never answered why, so why would you expect an advice?..
—SA

1 solution

Hi
You can use IsMouseCaptureWithinChanged event for TextBox, It will hit whenever you click on TextBox.
 
Share this answer
 
Comments
keerth516 17-Jul-13 14:37pm    
am not able to write any thing in textbox ...as soon as i clikc the text box to enter text it invoking this event and throws exception....any solution!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900