-
- VBForums
- Visual Basic
- Visual Basic .NET
- Make textbox announced after a push button is clicked
-
Nov 14th, 2009,06:57 PM #i Thread Starter Member Make textbox appear later on a button is clicked Hi How practice I make a textbox appear inside rich text box by clicking on a push button. I want the new textbox to appear where the cursor is Thank you -
Nov 14th, 2009,07:08 PM #two Re: Brand textbox announced after a button is clicked Maybe by explaining to us what you are trying to do, we tin can provide a better solution. For at present, as far as I know, you can't place a TextBox within of a RichTextBox because it is non a container. CodeBank contributions: Process Manager, Temp File Cleaner Originally Posted by SJWhiteley "game trainer" is the aforementioned as calling the act of robbing a banking concern "wealth redistribution".... -
November 14th, 2009,07:23 PM #3 Re: Brand textbox appear after a button is clicked I very much doubt that you actually want a TextBox to announced inside a RichTextBox. Presumably yous want the text that is in the TextBox to be added to the text that is in the RichTextBox. For any control derived from TextBoxBase (TextBox, RichTextBox, MaskedTextBox, etc.) yous only set the SelectedText property to insert text at the current caret position. If text is currently selected information technology will be replaced. E.g. vb.internet Code: -
myRichTextBox.SelectedText = myTextBox.Text -
Nov 14th, 2009,07:27 PM #four Thread Starter Member Re: Make textbox appear afterwards a button is clicked Originally Posted by weirddemon Perhaps past explaining to united states what you are trying to do, we tin can provide a better solution. For at present, equally far every bit I know, you tin can't place a TextBox inside of a RichTextBox because information technology is not a container. I want to make a program that allows to utilise maths symbols etc hands. For example for now it has 3 buttons, 1 which allows to enter sqrt symbol, one with powers, and one with fractions. So I desire two textboxes to announced (one on top of the other) in one case the fraction push button is clicked so that its easy to type in the numbers -
Nov 14th, 2009,07:48 PM #5 Re: Make textbox appear after a button is clicked Well, that but goes to show that a complete explanation is required, considering my assumption was incorrect. I just did this and it worked OK: Code: Public Class Form1 Individual Sub Button1_Click(ByVal sender As Arrangement.Object, ByVal e As System.EventArgs) Handles Button1.Click With Me.TextBox1 .Articulate() .Location = Me.PointToClient(Me.RichTextBox1.PointToScreen(Me.RichTextBox1.GetPositionFromCharIndex(Me.RichTextBox1.SelectionStart))) .Show() .BringToFront() .Select() End With End Sub Private Sub TextBox1_Leave(ByVal sender As Object, ByVal e Every bit System.EventArgs) Handles TextBox1.Leave Me.RichTextBox1.SelectedText = Me.TextBox1.Text Me.TextBox1.Hide() Terminate Sub End Class When the Button is clicked the TextBox appears and when information technology loses focus the text it contains is inserted into the RTB. EDIT: Note that I added the TextBox to the form commonly and set up its Visible belongings to False. I would also advise setting the Tab gild such that the RTB follows the TextBox. That way, when you're entering text into the TextBox you can but striking the Tab central and the TextBox will disappear and the RTB will have focus. Final edited by jmcilhinney; Nov 14th, 2009 at 07:51 PM. -
Nov 14th, 2009,08:10 PM #6 Thread Starter Member Re: Make textbox appear afterwards a button is clicked Originally Posted by jmcilhinney Well, that merely goes to evidence that a complete explanation is required, because my assumption was incorrect. I merely did this and it worked OK: Lawmaking: Public Form Form1 Private Sub Button1_Click(ByVal sender Equally Organization.Object, ByVal e As System.EventArgs) Handles Button1.Click With Me.TextBox1 .Clear() .Location = Me.PointToClient(Me.RichTextBox1.PointToScreen(Me.RichTextBox1.GetPositionFromCharIndex(Me.RichTextBox1.SelectionStart))) .Evidence() .BringToFront() .Select() Stop With End Sub Private Sub TextBox1_Leave(ByVal sender As Object, ByVal east As System.EventArgs) Handles TextBox1.Leave Me.RichTextBox1.SelectedText = Me.TextBox1.Text Me.TextBox1.Hibernate() End Sub End Class When the Push button is clicked the TextBox appears and when it loses focus the text it contains is inserted into the RTB. EDIT: Notation that I added the TextBox to the class normally and gear up its Visible belongings to False. I would also suggest setting the Tab lodge such that the RTB follows the TextBox. That way, when you're entering text into the TextBox you lot tin just hit the Tab cardinal and the TextBox will disappear and the RTB will accept focus. Thanks for the long code, but it doesnt work. It just clears all the text in the RTB -
Nov 14th, 2009,08:xviii PM #7 Re: Make textbox appear afterwards a button is clicked Originally Posted past oyeioyei Thanks for the long code, just it doesnt work. It just clears all the text in the RTB I tested it myself before I posted it and it works in VS 2008. Either you've done something wrong when implementing it for yourself or else you have selected all the text in the RTB first and then you lot haven't entered anything into the TextBox. Setting the SelectedText will replace the current selection. If nix is selected then the new text is inserted simply if something is already selected then information technology will be replaced. If the entire contents of the RTB is selected when the TextBox is shown and and so no text is entered before the TextBox is hidden, the entire contents of the RTB will exist replaced with an empty cord. Feel free to adjust the lawmaking equally you run across fit but, every bit is, it does exactly what it's supposed to do. -
Nov 14th, 2009,08:24 PM #viii Thread Starter Member Re: Make textbox appear later on a button is clicked Originally Posted by jmcilhinney I tested it myself before I posted it and it works in VS 2008. Either you've done something incorrect when implementing it for yourself or else you lot have selected all the text in the RTB first and then you haven't entered annihilation into the TextBox. Setting the SelectedText volition supercede the current selection. If goose egg is selected then the new text is inserted but if something is already selected and so it will be replaced. If the entire contents of the RTB is selected when the TextBox is shown and then no text is entered earlier the TextBox is hidden, the entire contents of the RTB volition be replaced with an empty string. Feel free to suit the code as you run across fit only, as is, it does exactly what it'southward supposed to practise. That is the thing, I have never used this kind of code before and when I was implementing information technology I just did it the way I constitute best even though I have no thought what it is. Dont empathise this code at all. Equally i said i am new to this so please Conduct with me. The code... Private Sub Button2_Click(ByVal sender As System.Object, ByVal east As Organisation.EventArgs) Handles Button2.Click With Me.txt1 .Clear() .Location = Me.PointToClient(Me.txt1.PointToScreen(Me.txt1.GetPositionFromCharIndex(Me.txt1.SelectionStart))) .Show() .BringToFront() .Select() End With TextBox1.Visible = True End Sub Private Sub TextBox1_TextChanged_1(ByVal sender As System.Object, ByVal due east As Organization.EventArgs) Handles TextBox1.TextChanged Me.txt1.SelectedText = Me.txt1.Text Me.txt1.Hide() End Sub Terminate Class Last edited past oyeioyei; Nov 14th, 2009 at 08:30 PM. -
Nov 14th, 2009,08:42 PM #nine Re: Brand textbox appear later a button is clicked 1. Create a new WinForms project and add a Button, a TextBox and a RichTextBox, in that order. 2. Set the Visible holding of the TextBox to False. 3. Open the code window and supersede the unabridged contents with the post-obit, which is a commented version of what I posted earlier: Lawmaking: Public Course Form1 Private Sub Button1_Click(ByVal sender Every bit Organisation.Object, ByVal e Every bit System.EventArgs) Handles Button1.Click With Me.TextBox1 'Clear the electric current contents of the TextBox. .Clear() 'Position the TextBox where the caret is in the RTB. .Location = Me.PointToClient(Me.RichTextBox1.PointToScreen(Me.RichTextBox1.GetPositionFromCharIndex(Me.RichTextBox1.SelectionStart))) 'Display the TextBox. .Show() 'Make sure the TextBox is in front of the RTB. .BringToFront() 'Set focus to the TextBox. .Select() End With End Sub Private Sub TextBox1_Leave(ByVal sender Every bit Object, ByVal e As System.EventArgs) Handles TextBox1.Leave 'Replace the electric current selection in the RTB with the contents of the TextBox. Me.RichTextBox1.SelectedText = Me.TextBox1.Text 'Hide the TextBox. Me.TextBox1.Hide() End Sub Terminate Class 4. Run the project. five. Click the RTB and start typing. 6. Click the Push button and notice the TextBox appear. 7. Go along typing and notice the text announced in the TextBox. viii. Hit the Tab key and find the TextBox disappear and it's contents appear in the RTB where the caret was. 9. Click in the RTB somewhere within the text. 10. Click the Button and blazon into the TextBox once again. eleven. Hit Tab once more and discover that the new text is inserted into the RTB where the caret was positioned. 12. Click and drah in the RTB to select some text. 13. Click the Push and blazon into the TextBox over again. 14. Hitting Tab again and notice that the new text has replaced what was selected. -
Nov 14th, 2009,08:51 PM #ten Thread Starter Member Re: Make textbox appear subsequently a button is clicked Originally Posted by jmcilhinney 1. Create a new WinForms projection and add a Push button, a TextBox and a RichTextBox, in that order. two. Set the Visible property of the TextBox to False. 3. Open the code window and supercede the entire contents with the post-obit, which is a commented version of what I posted earlier: Code: Public Class Form1 Private Sub Button1_Click(ByVal sender As Organisation.Object, ByVal east As System.EventArgs) Handles Button1.Click With Me.TextBox1 'Clear the current contents of the TextBox. .Clear() 'Position the TextBox where the caret is in the RTB. .Location = Me.PointToClient(Me.RichTextBox1.PointToScreen(Me.RichTextBox1.GetPositionFromCharIndex(Me.RichTextBox1.SelectionStart))) 'Display the TextBox. .Prove() 'Make sure the TextBox is in front of the RTB. .BringToFront() 'Set focus to the TextBox. .Select() End With Cease Sub Private Sub TextBox1_Leave(ByVal sender Every bit Object, ByVal e As Arrangement.EventArgs) Handles TextBox1.Leave 'Replace the current choice in the RTB with the contents of the TextBox. Me.RichTextBox1.SelectedText = Me.TextBox1.Text 'Hide the TextBox. Me.TextBox1.Hibernate() End Sub Stop Course 4. Run the project. 5. Click the RTB and first typing. 6. Click the Button and observe the TextBox appear. 7. Continue typing and detect the text appear in the TextBox. 8. Striking the Tab fundamental and find the TextBox disappear and it's contents appear in the RTB where the caret was. 9. Click in the RTB somewhere within the text. 10. Click the Button and blazon into the TextBox again. 11. Hit Tab again and notice that the new text is inserted into the RTB where the caret was positioned. 12. Click and drah in the RTB to select some text. 13. Click the Button and type into the TextBox again. fourteen. Hit Tab again and find that the new text has replaced what was selected. Cheers very much that style it works but i dont know why its not woking on my i. Is at that place a manner to type in a fraction like in word eqn so on top and bottom there is a text box, divided by a line to brand fraction that is waht I wanted to achieve by using this textbox method Last edited by oyeioyei; Nov 14th, 2009 at 08:56 PM. -
Nov 14th, 2009,09:04 PM #11 Re: Brand textbox appear after a push is clicked You tin merely do in a RichTextBox what is supported past the RTF specification. It basically just supports text, but allows you to add together markup to format the text with different fonts, colours, etc. What you're talkingabout goes beyond what RTF, and therefore the RichTextBox control, supports. If you want to display fractions like that and so yous'd have to employ GDI+ to describe them yourself because they cannot be represented that way in RTF. -
Nov 14th, 2009,09:xi PM #12 Thread Starter Member Re: Brand textbox appear after a push is clicked Originally Posted by jmcilhinney You tin can only do in a RichTextBox what is supported by the RTF specification. It basically simply supports text, only allows you to add markup to format the text with different fonts, colours, etc. What you're talkingabout goes beyond what RTF, and therefore the RichTextBox control, supports. If yous want to display fractions like that then you lot'd have to apply GDI+ to draw them yourself because they cannot be represented that mode in RTF. What nearly the method of using the textbox, the i u sent me code of. Any ideas why its non working on my current programme, on new it works -
Nov 14th, 2009,10:05 PM #13 Re: Brand textbox appear after a button is clicked -
- VBForums
- Visual Bones
- Visual Basic .Cyberspace
- Brand textbox appear later a button is clicked
Posting Permissions - You may not post new threads
- You may non post replies
- You may not post attachments
- You may not edit your posts
- BB code is On
- Smilies are On
- [IMG] code is On
- [VIDEO] code is On
- HTML code is Off
Forum Rules | Click Here to Expand Forum to Full Width |
0 Response to "Clicking the Same Button Again Clears Text Boxes Visual Basioc"
Enregistrer un commentaire