|
Rather than post processing of a text box, which will truncate user input, consider limiting it at the point of entry. This generally feels more natural to users as they do not get typing "thrown away" without them being aware in advance. You can set the TextBox.MaxLength property to 20 characters.
To pad the string to 20 characters, use
string paddedToTwentyChars = String.Format("{0,-20}", myTextBox.Text);
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
Ravi,
The following does the job simply.
Hope this helps,
Rob
string TwentyChar(string orig)
{
int len = orig.Length;
if (len < 20)
return orig.PadRight(20);
else if (len > 20)
return orig.Substring(0, 20);
else
return orig;
}
|
|
|
|
|
without conditionals:
orig.PadRight(20).Substring(0, 20)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Anyone know how to do this in C#? Same as this but programmatically?
Everything makes sense in someone's mind
|
|
|
|
|
|
Hi,
I am deploying a win app using a setup file which downloads and runs from a website.
1 How can I check for new version from withing the application and if possible to force the user to take this version?
2 I am using the settings.settings file to store user values. These are overwritten when a user takes an upgrade. How do I keep these settings? .
I have tried click once but found that if a user does not take an update he does not get another chance and I would have to recompile every time
milenalukic
|
|
|
|
|
ClickOnce[^]
You can code to check for updates each time the application is started and not run until the user updates.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
|
Hello Experts,
I have an Object of Polygon Which I am Drawing In A Rectangle. It Works Successfully.
But i have generate a problem While I want to Shift This Polygon to Left or Top.
So please help me for doing this operation.
Thanks
If you can think then I Can.
|
|
|
|
|
What is the problem?
How are you drawing it? Where are you drawing it? In the Paint event? Or somewhere else?
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
I have an Object of Polygon Which I want to Align Left.
If you can think then I Can.
|
|
|
|
|
I'm sure this is a language problem, but without better information it is impossible to work out how to help you.
Please, post the fragment of your code that draws the polygon - just the method should be enough - and enclose it in a "code block" by putting <pre> in front of it, and </pre> after it. That preserves the formatting and makes it easier to read:
With code block:
if (condition)
{
statement;
if (condition)
statement;
statement;
}
Without code block:
if (condition)
{
statement;
if (condition)
statement;
statement;
}
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
Hello Sir,
I am drawing Polygon and Now I want it to shift in Left Side.
In Case of Rectangle We Can Use the Rectangle.X = 0
But How to Shift Polygon.
Code For Drawing Polygon is given below :
Point point1 = new Point(50, 50);
Point point2 = new Point(100, 25);
Point point3 = new Point(200, 5);
Point point4 = new Point(250, 50);
Point point5 = new Point(300, 100);
Point point6 = new Point(350, 200);
Point point7 = new Point(250, 250);
public void DrawPolygonPoint(PaintEventArgs e)
{
Pen blackPen = new Pen(Color.Black, 3);
Point[] curvePoints =
{
point1,
point2,
point3,
point4,
point5,
point6,
point7
};
e.Graphics.DrawPolygon(blackPen, curvePoints);
}
If you can think then I Can.
|
|
|
|
|
Just change all the x-coordinates to move it to the left or right, change the y-coordinates to move it up or down.
|
|
|
|
|
 Good - you are drawing it in the Paint event.
The simplest way is to just add an offset into your curve constructor:
private void panel1_Paint(object sender, PaintEventArgs e)
{
DrawPolygonPoint(e);
DrawPolygonPoint(e, -10, -20);
DrawPolygonPoint(e, -20, 10);
}
Point point1 = new Point(50, 50);
Point point2 = new Point(100, 25);
Point point3 = new Point(200, 5);
Point point4 = new Point(250, 50);
Point point5 = new Point(300, 100);
Point point6 = new Point(350, 200);
Point point7 = new Point(250, 250);
public void DrawPolygonPoint(PaintEventArgs e)
{
DrawPolygonPoint(e, 0, 0);
}
public void DrawPolygonPoint(PaintEventArgs e, int xOffset, int yOffset)
{
Pen blackPen = new Pen(Color.Black, 3);
Point[] curvePoints =
{
AddOffset(point1, xOffset, yOffset),
AddOffset(point2, xOffset, yOffset),
AddOffset(point3, xOffset, yOffset),
AddOffset(point4, xOffset, yOffset),
AddOffset(point5, xOffset, yOffset),
AddOffset(point6, xOffset, yOffset),
AddOffset(point7, xOffset, yOffset)
};
e.Graphics.DrawPolygon(blackPen, curvePoints);
blackPen.Dispose();
}
private Point AddOffset(Point p, int xOffset, int yOffset)
{
return new Point(p.X + xOffset, p.Y + yOffset);
}
(NOTE: If you construct a graphics item, such as a pen, you should dispose of it when you are finished)
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
The Code Is Not Working Fine as Requirement.
I want to Place this Polygon to Left Side.
If you can think then I Can.
|
|
|
|
|
Then add a negative xOffset, and leave yOffset zero...
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
It will not work.
My Requirement is If I am Drawing Star or Triangle from Polygon and i want to shift (Align) it to Left.
If you can think then I Can.
|
|
|
|
|
It is maths that you are probably struggling with. Start with offset values of say 10. Then gradually increase or decrease it till you reach the right alignment.
|
|
|
|
|
So, find the minimum X coordinate of your polygon, and use a negative version of that as the xOffset.
Point[] shape = new Point[] { new Point(50, 50),
new Point(100, 250),
new Point(200, 5),
new Point(250, 50),
new Point(300, 100),
new Point(350, 200),
new Point(250, 250)};
public void DrawPolygonPoint(PaintEventArgs e)
{
Pen blackPen = new Pen(Color.Black, 3);
Pen redPen = new Pen(Color.Red, 1);
e.Graphics.DrawPolygon(redPen, shape);
int minX = int.MaxValue;
foreach (Point p in shape)
{
if (p.X < minX)
{
minX = p.X;
}
}
Point[] curvePoints = new Point[shape.Length];
int i = 0;
foreach (Point p in shape)
{
curvePoints[i++] = AddOffset(p, - minX, 0);
}
e.Graphics.DrawPolygon(blackPen, curvePoints);
redPen.Dispose();
blackPen.Dispose();
}
Draws the original in red, and a left aligned version in black. Note that I have moved your individual points into an array to make it easier to work with.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
Exactly i find it.
Thanks Sir.
If you can think then I Can.
|
|
|
|
|
Welcome!
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
your pens wear out quite easily, are you applying too much pressure to them? good thing you dispose them properly.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
They don't last like they used to!
Brushes seem to get bristly and have to be thrown out as well...
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
I don't think what r u talking about.
If you can think then I Can.
|
|
|
|
|