RichTextBox Not Showing Formatting Until Text Is Selected - vb.net

I have programmatically added a RichTextBox control to a form, but I seem to be experiencing a lot of issues when trying to format it. Please note that I have manually added the control through the GDI but also encounter the same problems.
Basically what is happening is that my control is drawn but uses the same initial background color as the form (even though I have manually specified a different color). The control also appears empty upon loading of the form, however, I can manually click the mouse the obtain a cursor where text 'should' be appearing.
If I click and drag inside the control, all of my text then appears with all of the formatting I defined. I have no idea what is causing this, but I have tried to Refesh the form, Refresh the Control, Update the control but nothing works. I have also tried using .Text, .SelectedText and .AppendText, as well as .SelectionColor and .SelectionBackColor.
My code is simply this:
Dim rtb As RichTextBox = New RichTextBox
rtb.Location = New Point(94, 229)
rtb.Size = New Size(608, 46)
rtb.BackColor = Color.FromArgb(38, 38, 38)
rtb.ForeColor = Color.LightGray
rtb.AppendText(_ticket.ticket_lastcomment)
Me.Controls.Add(rtb)
Yet it creates a new RichTextBox that is the same color as the form (Color.Control) and empty. No formatting is applied to the control until I highlight the text manually.
I have never come across this before.
UPDATE
After various trial and error and moving code, I have come to find that the piece of code preventing the drawing of the RichTextBox is this:
Me.animator = New FormAnimator(Me, FormAnimator.AnimationMethod.Centre, FormAnimator.AnimationDirection.Right, 200)
I apply a FormAnimator to the form to give it an effect upon opening. Removing this piece of code allows the RichTextBox to draw correctly.....strange.

Try this :)
rtb.rtf =_ticket.ticket_lastcomment

I know its a little late for this answer, but it may help future visitors.
All you have to do, is add first the RichTextBox to the form and then set the text:
Me.Controls.Add(rtb)
rtb.AppendText(_ticket.ticket_lastcomment)

Related

VB.NET end cell editing mode on DataGridView lost focus

I am building a WinForms application and I have a class called DecimalDataGridView that inherits the vb.net DataGridView. In this class I've defined an editing control class that essentially only permits the user to input numeric inputs into cells. This custom datagridview works perfectly whenever cells are edited and focus is changed to a different cell. However, I've noticed that when focus is lost outside the datagridview control (like another text box or control), the cell that was being edited (if it was in edit mode) doesn't leave edit mode and doesn't validate. This ends up messing up a bunch of other validation events in other controls, and pretty much breaks the form. The only way to resolve this issue is to re-enter the cell that was being edited, finish the edit, and then move focus to another cell in the datagridview.
To fix this issue, I'm trying to force-end the editing mode, whenever a cell is leaving (see my CellLeave event below.) I've tried to find solutions to this online, and it seems like people have had similar issues, but so far nothing has worked. The 'EndEdit' does not appear to work, nor do CommitEdit or CancelEdit. I've also tried toggling the current cell's read only property to see if that ends the edit mode, but no luck. Any solutions to this issue, or suggestions on different approaches are greatly appreciated. Thanks
Private Sub DecimalDataGridView_CellLeave(sender As DecimalDataGridView, e As EventArgs) Handles Me.CellLeave
EndEdit()
End Sub

Word 2010 ActiveX control forms - formatting issues

Hopefully a quick one
I am creating a form in Word with a Save macro that uses an ActiveX Label as a button. The label works fine as a button but I am having 2 issues:
when using the document in normal mode, the coding text in curly brackets for the label is still visible - see image
How do I get rid of this?
When printing the form, the button pushes the header text down a line:
You can see in the first picture that there is no gap here.
Thanks for your help.
(1) Press Alt+F9 to toggle off display of field codes (and make sure you're not in Design Mode).
(2) is impossible to be sure without having the document in front of me but...
Printing problems are notorious with ActiveX controls, which were designed for use with UserForms, not for the document surface. Your best bet for stability would be to use a one-row, two-column table with the button on the left and the address on the right.
Or use a MacroButton field code instead of an ActiveX control.

Access cell color value of datagridview when it has been set via the cellpainting event args

My searches regarding this have only turned up how to set the color of a datagridview cell, whether that be in the formatting, cell painting, or databound events.
The code that I'm trying to work with is currently setting the cellstyle.backcolor through the datagridview event args in the cellpainting event:
Private Sub dgvAncientCode_CellPainting(sender As Object, e As DataGridViewCellPaintingEventArgs) Handles dgvResults.CellPainting
If dgvAncientCode.Columns(e.ColumnIndex).Name = "Blah" Then
e.CellStyle.BackColor = Color.Red
End If
This works--the specified cells do show up as red--but how can I access this value elsewhere in code? When I check the cell.style it's set to the default, yet it displays on the screen as red.
I know there is a lot wrong with this code, but I'm still relatively new and I'm supporting a lot of legacy stuff that's comprised of every worst practice you can think of. I did come up with a workaround for this by setting the cell.style.backcolor instead of the e.CellStyle.BackColor, which lets me access the value later, but I'm also trying to understand what was happening with the original code. I hate making things work without understanding why, mainly because I know I might be missing something important.
I apologize if this isn't clear or if it's been asked before. I've searched for a couple hours here and elsewhere, so hopefully I didn't miss it.
Edit for additional information: There is a button click event that iterates through the datagridview using a for each loop. That is being used to set the cell color of a custom excel export class. This did not work because none of the cells in the datagridview had a value on the cell.style.backcolor property, even though they show as red in the form. If the cell displays as Red in the form, I should be able to access that somehow--at least, I think I should.
Try one of this. Maybe it can help you. "yourdatagrid.ControlStyle", "yourdatagrid.ItemStyle".

VB.Net UI is missing

I'm using Visual Studio 2012 to make a Vb.Net application.
In short, I added DotNetBar RibbonControl with some RibbonItems on it as my menu.
What happened is one of my tab is suddenly missing along with all the buttons in it.
I have searched for it on my Document Outline still no luck.
But what even more odd is, when I tried to recreate it with the same name, it shows an Alert "Property value is not valid" with message "The name AppPOButton is already in use by another component".
When I checked it on the form's Designer I do found this lines:
Me.AppPOButton = New DevComponents.DotNetBar.ButtonItem()
and
'AppPOButton
'
Me.AppPOButton.ButtonStyle = DevComponents.DotNetBar.eButtonStyle.ImageAndText
Me.AppPOButton.Image = Global.ProjectBMT.My.Resources.Resources.approval
Me.AppPOButton.ImageFixedSize = New System.Drawing.Size(40, 40)
Me.AppPOButton.ImagePosition = DevComponents.DotNetBar.eImagePosition.Top
Me.AppPOButton.Name = "AppPOButton"
Me.AppPOButton.SubItemsExpandWidth = 14
Me.AppPOButton.Text = "Approve"
Me.AppPOButton.Visible = False
and
Friend WithEvents AppPOButton As DevComponents.DotNetBar.ButtonItem
Is there anyone can explain why this is happening?
Thank you
This behavior is weird itself, but it's not a problem actually, All the Ribbon style works on "Containers", if you check your ribbon control and click the left-upper button will see these little arrows that move four containers, these objects hold the buttons, images and other controls. Within your design window in the right panel (Properties) you can still see the names of the controls you "lost" when you deleted your tab, wich is also a container.
Steps:
Add a container within your design view and Dock it into the Ribbon control Form.
Click on the uppper right boton (Right Arrow) and select "Layout Ribbon", this will adjust the lenght and hight of the controls conatained.
Add the tab that will contain all the controls you have.
The fact that they are still in the designer form is the prove that they still exist, This behavior is just a glitch in the position and order of the controls set above your form ;-)

Hide command button on word doc

I have a .doc with a command button (cmdStart) which opens a form.
After populating the form I click a button to close the form and populate the .doc.
I want to hide the initial cmdStart on the .doc as well when the form closes,
Ive tries document.shapes(1).visible=false and cmdStart.visible=false but none seems to work.
Any ideas?
thanks
(ps I cant just opne the form from the autonew, I need the cmdStart visible to begin with)
You have several options to deal with that. However, you won't be able to hide your command button but you will be able to remove it.
Removing a command button can be done by the following code:
Private Sub CommandButton1_Click()
CommandButton1.Select
Selection.Delete
End Sub
(Note that usually you would be able to hide text in Word by setting the font hidden, e.g. by calling Selection.Font.Hidden. However, this does not affect controls.)
If you deleted the button and you need it later on again you will have to re-create it. In that case it might be a good idea to mark the position of the button with a bookmark.
Another option would be to use a MACRO button field. Such a field can be inserted from the Insert Field dialog and can be used to launch a macro.
If you really wanted to "hide" the button, you could set the Height and Width to 0.75 and it's virtually gone. Then resize back to "show". I've also seen people put them inside tags and hide the tag. Hope this helps