|
First of all ArrayList is not recommended as the performance is not the best. See the Remarks section in ArrayList Class[^]
That said, as you cannot change the values as the Rectangle is a struct and not a class, it might be better if you implement an interface and/or an abstract base class, and then a class for each shape you want to have, Rectangle, Circle, Triangle etc. (Or whatever it is you want)
The specific shape classes all inherit the base class.
The benefit of this approach is that you can share common properties, such as Position and Size but also implement shape specific a Paint method for each class.
public abstract class Base
{
public Base()
{
location = new Point();
}
public abstract void Paint(Graphics g);
public string ShapeName { get; protected set; }
private Point location;
public Point Location
{
get
{
return location;
}
set
{
location = value;
}
}
private Size size;
public Size Size
{
get
{
return size;
}
set
{
size = value;
}
}
public int X
{
get
{
return location.X;
}
set
{
location.X = value;
}
}
}
public class Square : Base
{
public Square(Point location, Size size)
: base()
{
ShapeName = "Square";
Location = location;
Size = size;
}
public override void Paint(Graphics g)
{
}
}
Then
List<Base> shapes = new List<Base>();
shapes.Add(new Square(new Point(), new Size(30, 30)));
shapes[0].X = 10;
|
|
|
|
|
Thank you very much.
I can't understand very well, you mean that the best method is i need new a rectangle class inherit from BaseShape ,use location and Size property, and no need to use rectangle struct ,is it right?
|
|
|
|
|
You can also use a Rectangle struct internally inside the base class.
I just made a quick example to show the concept.
|
|
|
|
|
Hello,
I am looking to be able to control the child form that is created from showDialog(), basically I am trying to make a program similar to powerpoint, where you can control what is being shown on a child form. I have no code as I have not yet figured out how to do this, I am looking for any tutorials, lessons, or advise on how best to do it, or if it is even possible.
The other option I have is to use a chat server and manipulate it to do what I need, but that seems a bit over bearing for just some controls..
Thank you for any help
|
|
|
|
|
The only way to do this is to show the child form non-modally so that your calling thread remains available to process messages in the controller form. So you'd have to use the Show() method instead of ShowDialog().
(I think that's what it's called. )
A simple way to accomplish this is to make public methods on your child form class that are called from the controlling form. The controller can pass any data that way to the child form.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
This helped, Thank you
|
|
|
|
|
Actually, I have a follow up question if you could help a bit more,
I am using showDialog, but then sending data to the child through the public methods, as per your suggestion, but I was wondering, right before I close the child form, is there a way to send any info back to the parent form? (without causing an infinite loop?)
Thank you once again
|
|
|
|
|
If you are using ShowDialog(), which launches the child form modally, then yes, you could expose a public method on the parent form and call it from the child form as long as the function does not try to re-launch the child form.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I can't tell what you want from your description here. If you create a Form and show it using 'ShowDialog, what kind of "control" is it that you don't have ?
Are you doing a WinForm app, or WPF ? Or is this a web-based app: ASP.NET ?
If you want a PowerPoint type one-Form-at-a-time program, there are many easy ways to achieve that including, for example with WinForms:
1. use of a series of UserControls displayed one-at-a-time in a Panel, or Form.
2. using a "Main Form" as kind of a play controller, and presenting other Forms one-at-a-time.
3. using a TabControl
4. using a circular linked list to regulate the display of child-whatevers
More details, please.
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.
modified 7-Nov-15 3:10am.
|
|
|
|
|
randor wrote: I am trying to make a program similar to powerpoint
That will take a while
Best,
John
-- LogWizard Meet the Log Viewer that makes monitoring log files a joy!
|
|
|
|
|
//Copying the content of the fdf to final pdf
using (var pdfFlat = new FileStream(outputFileNameAndPath, FileMode.Open))
using (var pdfReader = new PdfReader(formLocation))
using (var pdfStamper = new PdfStamper(pdfReader, pdfFlat))
using (var fdfReader = new FdfReader(file))
{
var pdfForm = pdfStamper.AcroFields;
pdfForm.SetFields(fdfReader);
var obj = new List<string>();
foreach (KeyValuePair<string, acrofields.item=""> entry in pdfForm.Fields)
{
//FormField ff = new FormField();
//ff.Field_name = entry.Key.ToString();
int fieldType = pdfForm.GetFieldType(entry.Key.ToString(CultureInfo.InvariantCulture));
if (fieldType == 2) //2 stands for check boxes
obj.Add(entry.Key);
}
const string path = @"Fonts/AdobePiStd.otf"; //@"Fonts/AdobePiStd.otf";
var customfont = BaseFont.CreateFont(path, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
//var font = new Font(customfont, 12);
foreach (var variable in obj)
{
pdfForm.SetFieldProperty(variable, "textfont", customfont, null);
}
pdfStamper.FormFlattening = true;
pdfStamper.Writer.CloseStream = false;
//string s = "My expensive custom font.";
//doc.Add(new Paragraph(s, font));
fdfReader.Close();
pdfStamper.Close();
pdfReader.Close();
pdfFlat.Close();
}
We are trying to embed a custom font to the PDF, but it is not applied to generated PDF. Above it he code which we implemented and it is not working.
can someone suggest solution, it would be really appreciated ?
|
|
|
|
|
Something like this[^] perhaps?
|
|
|
|
|
Known Variables:
1 Loan Amount : 100000
2 Period : 36 months
3 Installment : per Quarter 10500
We have to find Interest Rate for quarterly payment frequency having monthly compounding?
Answer of this is = 17.7802951925.
Standard Emi Formula
EMI = P*r*((1+r)^n)/((1+r)^n-1)
I have calculated Monthly installment with help of following code
m_Principle = p;
m_MonthalyPayments = m;
m_NoOfMonths = n;
double temp = (m_MonthalyPayments / m_Principle);
double answer = temp;
double diff = 100;
double numerator = 0;
double denomenator = 0;
double accuracy = .00001;
int maxIteration = 1000;
int index = 0;
try
{
for (index = 0; ((diff > accuracy) && (index < maxIteration)); index++)
{
temp = answer;
numerator = (m_Principle * (temp / m_MonthalyPayments)) + Math.Pow((1 + temp), -m_NoOfMonths) - 1;
denomenator = (m_Principle / m_MonthalyPayments) - (m_NoOfMonths * Math.Pow((1 + temp), (-m_NoOfMonths - 1)));
answer = temp - (numerator / denomenator);
diff = answer - temp;
if (diff < 0)
{
diff = -diff;
}
}
answer *= 1200;
if ((answer < 0) || Double.IsNaN(answer) || (index == maxIteration))
{
throw new ArithmeticException();
}
}
catch (Exception ex)
{
throw new Exception(ex.Message, ex);
}
return answer;
With this Result for monthly calculation are matching correctly. For Quarterly installments i have changed only 12000 to 400 to multiply answer in code.
|
|
|
|
|
1. so what is the question, exactly?
2. this code:
Member 10498544 wrote: catch (Exception ex)
{
throw new Exception(ex.Message, ex);
}
is basically useless, not to say dangerous - why have it?
Best,
John
-- LogWizard Meet the Log Viewer that makes monitoring log files a joy!
|
|
|
|
|
Thank you for your help..
My basic question is
Calculate Interest Rate if i know principal amount, loan Period, installment amount but installment is not monthly it is quarterly.
|
|
|
|
|
So is there a different formula?
Best,
John
-- LogWizard Meet the Log Viewer that makes monitoring log files a joy!
|
|
|
|
|
anyone can give me an advice for improving this piece code, it give me a complexity of score of 10. There is something telling in back of my mind that it can be improve, but this is the best i can do. arggg
public override bool Validate(Control control, object value)
{
if (value == null && !_IsAllowNull)
{
ErrorText = "Please provided valid number without a decimal point.";
return false;
}
else
{
if (value.ToString().Contains("."))
{
ErrorText = "Decimal value is not allowed";
return false;
}
else
{
if (!value.IsNumber())
{
ErrorText = "Please provided valid number without a decimal point.";
return false;
}
else
{
if (value.ToInt() < _minValue || value.ToInt() > _maxValue)
{
ErrorText = "Value should not be greater than " + _maxValue + " or less than " + _minValue;
return false;
}
}
}
}
return true;
}
I will appreciate for any help will come.
|
|
|
|
|
How's this:
public override bool Validate(Control control, object value)
{
string err = null;
if (value == null && !_IsAllowNull)
err = "Please provided valid number without a decimal point.";
else if (value.ToString().Contains("."))
err = "Decimal value is not allowed";
else if (!value.IsNumber())
err = "Please provided valid number without a decimal point.";
else if (value.ToInt() < _minValue || value.ToInt() > _maxValue)
err = "Value should not be greater than " + _maxValue + " or less than " + _minValue;
if ( err != null)
ErrorText = err;
return err == null;
}
Best,
John
-- LogWizard Meet the Log Viewer that makes monitoring log files a joy!
|
|
|
|
|
Thank you, I will try it.
|
|
|
|
|
I'm failing to see the "less complexity" here ?
For my personal use, it's even "more complex".
|
|
|
|
|
I certainly beg to differ. The code is much more readable.
But please, provide an alternative You may be right
Best,
John
-- LogWizard Meet the Log Viewer that makes monitoring log files a joy!
|
|
|
|
|
It's probably a matter of taste.
I personally hate the lack of brackets, because it makes it hard to insert a statement if the code needs modification, but in the end it's up to the developer. You did remove the multiple exit points .
|
|
|
|
|
Thanks
The lack of brackets is taste-dependent for sure I like to make code as short as possible without sacrificing readability.
Having said that, about code needing modification - resharper makes it extremely easy to do. Namely , you open the bracket {, go after the statement, and it will write the closing bracket for you.
Best,
John
-- LogWizard Meet the Log Viewer that makes monitoring log files a joy!
|
|
|
|
|
It's obvious the code shown here depends on a context which you don't show; a guess would be that this code is being used with a 3rd. party Control:
1. there's no override named 'Validate for either a WinForm, or a sub-classed TextBox.
2. you never do anything with the Control passed as a parameter.
3. the string assignments to 'ErrorText use (probably) a Property in the context here; a guess would be that the 'setter of that Property has "side-effects."
4. the 'Value parameter here comes in as an Object, but clearly it is a string.
If I thought the user entering text here was going to type in an integer most of the time:
Int32 _minValue = 0;
Int32 _maxValue = 100;
Int32 trialvalue;
private bool checkInt(object val)
{
string strval = val.ToString();
if (Int32.TryParse(strval, out trialvalue))
{
if (trialvalue >= _minValue && trialvalue <= _maxValue) return true;
return false;
}
return false;
} Comments:
1. measuring the "complexity" of this code is probably useless since (guess) its structure is dictated by the whatever you over-ride, and depends on that for error-reporting.
2. I'd certainly want to get the string creation used for the error messages here outside of the method; some of them can be declared string constants.
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.
|
|
|
|
|
Thank you,
Yes you are right, it was inherited from a third party control, but the parameter Control will be handled by the base class, and the ErrorText is also a property.
basically the type of the parameter Value will defend on how it was implemented. but in this case, while the input will came from a user using either a textbox or other winform controls. so it was a string then will be validated if it is a integer.
here is my solution
public override bool Validate(Control control, object value)
{
if (value == null && !_IsAllowNull)
{
ErrorText = "Please provided valid number without a decimal point.";
return false;
}
if (value.ToString().Contains("."))
{
ErrorText = "Decimal value is not allowed";
return false;
}
if (!value.IsNumber())
{
ErrorText = "Please provided valid number without a decimal point.";
return false;
}
if (value.ToInt() < _minValue || value.ToInt() > _maxValue)
{
ErrorText = "Value should not be greater than " + _maxValue + " or less than " + _minValue;
return false;
}
return true;
}
the complexity of this solution just drop 3 point.
but I like your solution, I will try to implement it.
once again, thank you.
|
|
|
|