How to underline text in Visual Basic (with Visual Studio 2010) - visual-studio-2010

I have a problem with underline text after press a button in Visual Basic. I'm using Visual Studio 2010 and I red in tutorial that in button method I have to use for example:
lbltext.FontUnderline = True
But I don't have variable "FontUnderline". Of course I was trying to find other variable or function to do this but without success. Anyone know how to do this in Visual Studio?

An inline answer looks like this:
Me.lbltext.Font = New Font(lbltext.Font, FontStyle.Underline)
This would save multiple lines of code.

Or the old way of doing it was to instance a new font
Font standardFont = new Font(lblText.Font)
Font underFont = new Font(standardFont,FontStyle.Underline)
Then just set the Font property of the relevant controls to the one you want.

Took the example of #Tony Hopkinson and added some small changes to make this work for VB.NET
So this is the syntax for VB.NET
Dim standardFont As Font = lblExportDate.Font
Dim underFont As New Font(standardFont, FontStyle.Underline)
Me.lblExportDate.Font = underFont

I think you are missing a dot here.
It should be lbltext.Font.Underline = true

Related

Visual Studio "code alignment" extension not working

I am using visual studio 2013, I am using an extension called "Code Alignment". After I apply the alignment and try to beautify the code, the visual studio removes the alignment.
I already checked the options in:
Option > Text Editor:
Tabs
Keep tabs
Do you have a solution for this?
ie:
before formatting:
var previousLowAddress = new string[1];
var previousMedAddresses = new string[1];
var previousHighAddresses = new string[1];
after visual studio formatting:
var previousLowAddress = new string[1];
var previousMedAddresses = new string[1];
var previousHighAddresses = new string[1];
Most likely, the problem is the font you are using is not "monospaced". This means different characters can take different amount of space, which will break the math the CodeAlignment plugin will do for you.
Try changing the Text Editor font to a monospaced type, such as "Consolas".
I tested this locally using Consolas and Microsoft YaHei UI fonts. As expected, the monospaced font (consolas) shows the correct alignment, and the Proportional font (Microsoft YaHei UI) does not.
VS has auto formatting enabled by default for c#. The options are in Text Editor\C#\Formatting.
You may need to disable all option in these category.
The productivity power tools extension also has a feature which formats the document on save. So if you use these extension you may disable the feature.
The built-in c# auto formatting honors indenting assignments, but if you try to indent round brackets/operators (as code alignment does), the extra whitespace will be removed by formatting.

How can I stop autoformatting of comments in Visual Studio 2010?

I like to indent my comments. Visual Studio 2010 removes the indenting format I make. How can I prevent that from happening?
Here is an example of what I am talking about. Before I code, I comment. It helps me to keep the picture of where I want to go when things get convoluted. So if I am going to code a lab coat I will write the comments for that part like this:
//Make lab coat
//Add pockets
//Add pen to top pocket
//Add buttons
//Add Name Tag
//Put Name On Name Tag
And then I would go back in and fill in the code for the commented section. This is just an example of formatting, lets not get into the semantics of lab coat implementation.
However, in Visual Studio 2010, if I start adding some code, the auto-formatter will remove all of the indentation for the comments. I tried looking at the editor options but couldn't figure out if the setting existed for this case.
How can I prevent Visual Studio 2010 from removing these indentations?
Have you considered adding your indentation after the double forward slashes?
I have this workaround, but I was hoping for a more legit method for accomplishing this.
//Build lab coat
{
//Add Pockets
{
//Add pen to top pocket
}
//Add Buttons
{
}
//Add Name Tag
{
//Add name to name tag
}
}

Disable *all* code formatting in Visual Studio 2010

I wish to disable all code formatting in Visual Studio 2010, with the intention of selectively switching options back on as I see fit.
Currently I have a specific problem that refuses to go away; When I add the final brace in the code block below, Visual Studio 2010 reformats the code for the entire switch statement above that point, placing each line against the margin (removes leading whitespace on each line). I've switched off every setting in Tools/Options/C#/Formatting to no avail. Is there an overriding 'Disable all formatting' option? Thanks.
switch(fractionalDigits)
{
case 0:
if(significand > 107374u)
{
if(truncateRange)
{
significand = 1073741823u;
}
else
{
result = FixedPointDecimal.Null;
return false;
}
}
else
{
UPDATE: The specific problem above was caused by additional formatting options being added by the Power Tools. The additional formatting options seem to interact with the built in logic an odd way.
Tools > Options > Text Editor > C# > Formatting > Indentation > Indent case labels
You could try the following:
Create a color theme with nearly no color. So you could readjust each code elements color step by step.
You can use the following tool to generate a no color theme:
Theme generator
Set the constrast to the left and main and foreground color to white.

How to make selection color be "on top" when background color for any text element is set in Visual Studio 2010 editor

Faced problem while setting background color for any element in Visual Studio 2010 editor. Selection color doesn't override this background color. So then it's very inconvenient to work with selections in editor.
Case when only string literal is selected it's almost impossible to distinguish colors and see what part of string is selected.
Is there any possibility to fix the problem by changing some options? Or it's a Visual Studio bug?
This is new VS2010 behavior which unfortunately is deliberate. However, Noah Richards (from the editor team) has written a couple of extensions that help mitigate the new behavior:
The first is an extension that draws a border around the selection (the main feature of the extension is a gradient background, but the border is what makes it really useful for me).
Second is an extension to change Selection Foreground color.

Programmatically enforce capitalization in Visual Studio 2008?

What is the easiest way to programmatically force capitalization of keywords in Visual Studio 2008?
We work with a proprietary command delimited language (like HTML). We are attempting to migrate from an older editor to Visual Studio 2008. Our coding standards are to capitalize the commands. The old editor is customized to recognize the command begin delimiter and to force capitalization until the end delimiter is typed or the escape key is pressed.
What's the best way to do that in Visual Studio 2008? Can it be done with a macro or an add-in?
(Edited 1-12-2009)
Thank you for the suggestions so far. I don't think they answer my question.
Clarifications:
The previous editor was CodeWright so the customizations there are not portable to visual studio.
The source code is not C#. StyleCop seems to be specifically for C#. Our language is similar to markup languages like HTML but with different delimiter characters and commands.
I am trying to actually capitalize as the developer types, not remind them about proper capitalization. Since the commands are all delimited our current editor actually turns the Caps Lock on when the beginning delimiter is typed. When the end delimiter or the escape key is pressed the caps lock is turned back off. This is independent of the state of the Caps Lock on the keyboard.
Try out StyleCop, available from Microsoft's web site. You might have to adjust the rule-set for your specific coding standards. For the coding standards we use, it was almost perfect out of the box.
While time consuming, this SO post shows you how to add tags to the validation setup in VS2005. I don't think the method changed in 2008.
If you are moving from an older version of Visual Studio you may be able to just import your old settings and custom tags.
This may not be the best solution but here is what I came up with.
Use macros to capture Key Press Events.
Here's how:
In Visual Studio go to the Tools->Macros->Macros IDE menu
Double Click "MyMacros" to see the different parts
Double Click "EnvironmentEvents"
Add the following code within the Environment Events module.
Save the file and return to the regular VS IDE to test.
Private My_AutoCaps As Boolean = False
Private Sub TextDocumentKeyPressEvents_BeforeKeyPress(ByVal Keypress _
As String, ByVal Selection As EnvDTE.TextSelection, _
ByVal InStatementCompletion As Boolean, ByRef CancelKeyPress As Boolean) _
Handles TextDocumentKeyPressEvents.BeforeKeyPress
Dim fileName As String = UCase(Selection.DTE.ActiveDocument.Name)
If ( fileName.EndsWith(".CPI") ) Then
If (My_AutoCaps) Then
'MsgBox(Keypress)
If (Keypress = "(" Or Keypress = ":") Then
'MsgBox("End of command character pressed.")
My_AutoCaps = False
Return
ElseIf (Keypress >= "a" And Keypress <= "z") Then
'MsgBox("Letter pressed.")
Selection.Text = UCase(Keypress)
CancelKeyPress = True
End If
Else 'AutoCap is not on yet
If (Keypress = "^") Then
'MsgBox("You pressed the Start Command character.")
My_AutoCaps = True
Return
End If
End If
End If
End Sub
This macro is limited to *.CPI files.
I have not figured out how to capture the Esc key yet but this will work for now.

Resources