StringFormat.ToString Método
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Convierte este objeto StringFormat en una cadena legible para el usuario.
public:
override System::String ^ ToString();
public override string ToString ();
override this.ToString : unit -> string
Public Overrides Function ToString () As String
Devoluciones
Representación en forma de cadena de este objeto StringFormat.
Ejemplos
El ejemplo siguiente está diseñado para su uso con Windows Forms y requiere PaintEventArgse
, que es un parámetro del Paint controlador de eventos. El código realiza las siguientes acciones:
Convierte un StringFormat objeto en una cadena.
Dibuja la cadena.
Cambia algunas propiedades del StringFormat objeto .
Dibuja la cadena. La cadena será diferente porque las propiedades del StringFormat objeto han cambiado.
void ToStringExample( PaintEventArgs^ e )
{
Graphics^ g = e->Graphics;
SolidBrush^ blueBrush = gcnew SolidBrush( Color::FromArgb( 255, 0, 0, 255 ) );
System::Drawing::Font^ myFont = gcnew System::Drawing::Font( "Times New Roman",14 );
StringFormat^ myStringFormat = gcnew StringFormat;
// String variable to hold the values of the StringFormat object.
String^ strFmtString;
// Convert the string format object to a string (only certain information
// in the object is converted) and display the string.
strFmtString = myStringFormat->ToString();
g->DrawString( String::Format( "Before changing properties: {0}", myStringFormat ), myFont, blueBrush, 20, 40 );
// Change some properties of the string format
myStringFormat->Trimming = StringTrimming::None;
myStringFormat->FormatFlags = (StringFormatFlags)(StringFormatFlags::NoWrap | StringFormatFlags::NoClip);
// Convert the string format object to a string and display the string.
// The string will be different because the properties of the string
// format have changed.
strFmtString = myStringFormat->ToString();
g->DrawString( String::Format( "After changing properties: {0}", myStringFormat ), myFont, blueBrush, 20, 70 );
}
public void ToStringExample(PaintEventArgs e)
{
Graphics g = e.Graphics;
SolidBrush blueBrush = new SolidBrush(Color.FromArgb(255, 0, 0, 255));
Font myFont = new Font("Times New Roman", 14);
StringFormat myStringFormat = new StringFormat();
// String variable to hold the values of the StringFormat object.
string strFmtString;
// Convert the string format object to a string (only certain information
// in the object is converted) and display the string.
strFmtString = myStringFormat.ToString();
g.DrawString("Before changing properties: " + myStringFormat,
myFont, blueBrush, 20, 40);
// Change some properties of the string format
myStringFormat.Trimming = StringTrimming.None;
myStringFormat.FormatFlags = StringFormatFlags.NoWrap
| StringFormatFlags.NoClip;
// Convert the string format object to a string and display the string.
// The string will be different because the properties of the string
// format have changed.
strFmtString = myStringFormat.ToString();
g.DrawString("After changing properties: " + myStringFormat,
myFont, blueBrush, 20, 70);
}
Public Sub ToStringExample(ByVal e As PaintEventArgs)
Dim g As Graphics = e.Graphics
Dim blueBrush As New SolidBrush(Color.FromArgb(255, 0, 0, 255))
Dim myFont As New Font("Times New Roman", 14)
Dim myStringFormat As New StringFormat
' String variable to hold the values of the StringFormat object.
Dim strFmtString As String
' Convert the string format object to a string (only certain
' information in the object is converted) and display the string.
strFmtString = myStringFormat.ToString()
g.DrawString("Before changing properties: ", myFont, blueBrush, _
20, 40, myStringFormat)
' Change some properties of the string format.
myStringFormat.Trimming = StringTrimming.None
myStringFormat.FormatFlags = StringFormatFlags.NoWrap Or _
StringFormatFlags.NoClip
' Convert the string format object to a string and display the
' string. The string will be different because the properties of
' the string format have changed.
strFmtString = myStringFormat.ToString()
g.DrawString("After changing properties: ", myFont, blueBrush, _
20, 70, myStringFormat)
End Sub
Comentarios
Solo se convierte el valor de la FormatFlags propiedad .
Se aplica a
Comentarios
https://aka.ms/ContentUserFeedback.
Próximamente: A lo largo de 2024 iremos eliminando gradualmente GitHub Issues como mecanismo de comentarios sobre el contenido y lo sustituiremos por un nuevo sistema de comentarios. Para más información, vea:Enviar y ver comentarios de