मैं 90 डिग्री घुमाए गए लेबल को दिखाना चाहता हूं (इसलिए मैं शीर्षक के रूप में तालिका के शीर्ष पर उनमें से एक गुच्छा डाल सकता हूं)। क्या इसे करने का कोई आसान तरीका है?मैं सी # में एक लेबल कैसे घुमा सकता हूं?
10
A
उत्तर
22
आपको अपना खुद का लिखना होगा या कस्टम नियंत्रण का उपयोग करना होगा।
ए The Code Project लेख जो आप शुरू कर सकते हैं Customized Text - Orientated Controls in C# - Part I (Label Control) है। इसमें अतिरिक्त कार्यक्षमता है, इसलिए यदि आप चाहें तो इसे नीचे ट्रिम करने में सक्षम होना चाहिए।
/// <summary>
/// This is a lable, in which you can set the text in any direction/angle
/// </summary>
#region Orientation
//Orientation of the text
public enum Orientation
{
Circle,
Arc,
Rotate
}
public enum Direction
{
Clockwise,
AntiClockwise
}
#endregion
public class OrientedTextLabel : System.Windows.Forms.Label
{
#region Variables
private double rotationAngle;
private string text;
private Orientation textOrientation;
private Direction textDirection;
#endregion
#region Constructor
public OrientedTextLabel()
{
//Setting the initial condition.
rotationAngle = 0d;
textOrientation = Orientation.Rotate;
this.Size = new Size(105,12);
}
#endregion
#region Properties
[Description("Rotation Angle"),Category("Appearance")]
public double RotationAngle
{
get
{
return rotationAngle;
}
set
{
rotationAngle = value;
this.Invalidate();
}
}
[Description("Kind of Text Orientation"),Category("Appearance")]
public Orientation TextOrientation
{
get
{
return textOrientation;
}
set
{
textOrientation = value;
this.Invalidate();
}
}
[Description("Direction of the Text"),Category("Appearance")]
public Direction TextDirection
{
get
{
return textDirection;
}
set
{
textDirection = value;
this.Invalidate();
}
}
[Description("Display Text"),Category("Appearance")]
public override string Text
{
get
{
return text;
}
set
{
text = value;
this.Invalidate();
}
}
#endregion
#region Method
protected override void OnPaint(PaintEventArgs e)
{
Graphics graphics = e.Graphics;
StringFormat stringFormat = new StringFormat();
stringFormat.Alignment = StringAlignment.Center;
stringFormat.Trimming = StringTrimming.None;
Brush textBrush = new SolidBrush(this.ForeColor);
//Getting the width and height of the text, which we are going to write
float width = graphics.MeasureString(text,this.Font).Width;
float height = graphics.MeasureString(text,this.Font).Height;
//The radius is set to 0.9 of the width or height, b'cos not to
//hide and part of the text at any stage
float radius = 0f;
if (ClientRectangle.Width<ClientRectangle.Height)
{
radius = ClientRectangle.Width *0.9f/2;
}
else
{
radius = ClientRectangle.Height *0.9f/2;
}
//Setting the text according to the selection
switch (textOrientation)
{
case Orientation.Arc:
{
//Arc angle must be get from the length of the text.
float arcAngle = (2*width/radius)/text.Length;
if(textDirection == Direction.Clockwise)
{
for (int i=0; i<text.Length; i++)
{
graphics.TranslateTransform(
(float)(radius*(1 - Math.Cos(arcAngle*i + rotationAngle/180 * Math.PI))),
(float)(radius*(1 - Math.Sin(arcAngle*i + rotationAngle/180*Math.PI))));
graphics.RotateTransform((-90 + (float)rotationAngle + 180*arcAngle*i/(float)Math.PI));
graphics.DrawString(text[i].ToString(), this.Font, textBrush, 0, 0);
graphics.ResetTransform();
}
}
else
{
for (int i=0; i<text.Length; i++)
{
graphics.TranslateTransform(
(float)(radius*(1 - Math.Cos(arcAngle*i + rotationAngle/180*Math.PI))),
(float)(radius*(1 + Math.Sin(arcAngle*i + rotationAngle/180*Math.PI))));
graphics.RotateTransform((-90 - (float)rotationAngle - 180*arcAngle*i/(float)Math.PI));
graphics.DrawString(text[i].ToString(), this.Font, textBrush, 0, 0);
graphics.ResetTransform();
}
}
break;
}
case Orientation.Circle:
{
if (textDirection == Direction.Clockwise)
{
for(int i=0;i<text.Length;i++)
{
graphics.TranslateTransform(
(float)(radius*(1 - Math.Cos((2*Math.PI/text.Length)*i + rotationAngle/180*Math.PI))),
(float)(radius*(1 - Math.Sin((2*Math.PI/text.Length)*i + rotationAngle/180*Math.PI))));
graphics.RotateTransform(-90 + (float)rotationAngle + (360/text.Length)*i);
graphics.DrawString(text[i].ToString(), this.Font, textBrush, 0, 0);
graphics.ResetTransform();
}
}
else
{
for(int i=0;i<text.Length;i++)
{
graphics.TranslateTransform(
(float)(radius*(1 - Math.Cos((2*Math.PI/text.Length)*i + rotationAngle/180*Math.PI))),
(float)(radius*(1 + Math.Sin((2*Math.PI/text.Length)*i + rotationAngle/180*Math.PI))));
graphics.RotateTransform(-90 - (float)rotationAngle - (360/text.Length)*i);
graphics.DrawString(text[i].ToString(), this.Font, textBrush, 0, 0);
graphics.ResetTransform();
}
}
break;
}
case Orientation.Rotate:
{
//For rotation, who about rotation?
double angle = (rotationAngle/180)*Math.PI;
graphics.TranslateTransform(
(ClientRectangle.Width+(float)(height*Math.Sin(angle))-(float)(width*Math.Cos(angle)))/2,
(ClientRectangle.Height-(float)(height*Math.Cos(angle))-(float)(width*Math.Sin(angle)))/2);
graphics.RotateTransform((float)rotationAngle);
graphics.DrawString(text,this.Font,textBrush,0,0);
graphics.ResetTransform();
break;
}
}
}
#endregion
}
6
आप Windows ToolStrip नियंत्रण पर एक नज़र ले जा सकते हैं:
और यहाँ से कुछ कोड ब्याज की है कि है। इसमें टेक्स्टडिरेक्शन का एक विकल्प है जिसे वर्टिकल 9 0 या वर्टिकल 270 पर सेट किया जा सकता है और यह आपके लेबल टेक्स्ट को उचित दिशा में घुमाएगा।
अवलोकन: ToolStrip Class (MSDN)
इसके उपयोग पर लघु वीडियो: http://msdn.microsoft.com/en-us/vstudio/bb798042 रोटेशन के लिए रोटेशन के लिए 03:05 विशेष रूप से देखते हैं।
संबंधित मुद्दे
- 1. मैं एक ggplot को परिदृश्य में कैसे घुमा सकता हूं?
- 2. मैं सी ++ तारों के वेक्टर पर कैसे घुमा सकता हूं?
- 3. मैं एक छवि को कैसे घुमा सकता हूं?
- 4. मैं राफेल.जेएस के साथ एक div कैसे घुमा सकता हूं?
- 5. आवृत्ति डोमेन में मैं छवि को कैसे घुमा सकता हूं?
- 6. मैं इंटरफ़ेस बिल्डर में UIImageView को कैसे घुमा सकता हूं?
- 7. मैं 3 डी सरणी कैसे घुमा सकता हूं?
- 8. मैं अपने सरणी को कैसे घुमा सकता हूं?
- 9. एक्शनस्क्रिप्ट: मैं टेक्स्ट फ़ील्ड को कैसे घुमा सकता हूं?
- 10. मैं आईओएस पर कस्टम स्पलैश स्क्रीन कैसे घुमा सकता हूं?
- 11. एंड्रॉइड, मैं एक निश्चित बिंदु के चारों ओर एक तीर (छवि) कैसे घुमा सकता हूं?
- 12. तीन.जेएस - मैं एक विशिष्ट बिंदु के चारों ओर एक सिलेंडर कैसे घुमा सकता हूं?
- 13. मैं पर्ले में बिल्कुल उसी तरह दो सरणी कैसे घुमा सकता हूं?
- 14. रूबी के लिए नया - मैं एक स्ट्रिंग को कैसे घुमा सकता हूं?
- 15. मैं extjs में अलग-अलग टेक्स्टफील्ड लेबल पर लेबल चौड़ाई कैसे सेट कर सकता हूं?
- 16. रेल 3 - मैं लेबल सहायक में टेक्स्ट-लेबल कैसे अनुकूलित कर सकता हूं?
- 17. मैं xCode 4 इंटरफ़ेस बिल्डर टूल चीज़ में विंडो कैसे घुमा सकता हूं?
- 18. मैं टिंकर कैनवास पर पाइथन में बहुभुज कैसे घुमा सकता हूं?
- 19. मैं सी # में एक संदेश बॉक्स कैसे बना सकता हूं?
- 20. मैं सी # में एक स्पलैश स्क्रीन कैसे जोड़ सकता हूं?
- 21. मैं सी # में एक सूची कैसे छीन सकता हूं?
- 22. मैं आर में एक किंवदंती में लेबल और प्रतीकों को कैसे बदल सकता हूं?
- 23. मैं एक सी ++ प्रोग्राम एक आइकन कैसे दे सकता हूं?
- 24. मैं एक WPF लेबल में पाठ के चारों ओर मार्जिन कैसे हटा सकता हूं?
- 25. मैं Django रूप में एक लेबल बोल्ड कैसे बना सकता हूं?
- 26. मैं एंड्रॉइड एमुलेटर को टेस्ट कोड से कैसे घुमा सकता हूं?
- 27. मैं iTextSharp तालिका सीमा के कोनों को कैसे घुमा सकता हूं?
- 28. मैं अपने हाईचर्ट्स बार चार्ट को कैसे घुमा सकता हूं ताकि इसकी ऊर्ध्वाधर, क्षैतिज न हो?
- 29. मैं अपने ऊपरी दाएं कोने से UIView 90 डिग्री को कैसे एनिमेट/घुमा सकता हूं?
- 30. मैं एक नया रंग कैसे बना सकता हूं?
दूसरा लिंक टूटा हुआ प्रतीत होता है। –
@ पीटर मॉर्टेंसन अब उपयोग योग्य होना चाहिए। बेहद आसान होने के लिए –
+1। – adam