|
Lord Kixdemp wrote: Well, as you can see, the values have to be as I had them:
http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
Then you can't combine them.
---
It's amazing to see how much work some people will go through just to avoid a little bit of work.
|
|
|
|
|
Hello,
I have a class let us call it Rect.cs with an internal System.Drawing.Rectangle object called rect instantiated in the constructor of class Rect.
Rect.cs has also a
void Paint(Graphics g)
{
g.FillRectangle(Brushes.Red,rect);
}
In my Windows form called Form1 i have :
a button with the click event handler. It creates a myClass object. After creating the object i call this.Invalidate() for the form to redraw.
I also have the Paint method for the window form that calls the Paint() method for the Rect object
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
rectObj.Paint(e.Graphics);
}
But it doesn't happen anything?!
Something important i've missed regarding redrawing or so?
Explanations with additional pseudo would be great !
Thanks from a tired guy!
|
|
|
|
|
I suggest you add something (such as Console.WriteLine statements) to make sure
if and when your Form1_Paint and Rect.Paint methods get called.
Are you sure rect bounds are such that it is visible inside your form ?
Did you print them out ? Could it be covered by something else ?
When a program does not behave to expectations, dont trust any part unless you have
seen proof of it working properly (I prefer log lines such as Console.WriteLine!)
Luc Pattyn
|
|
|
|
|
Hi,
I had a MessageBox.Show() in my rect.Paint() and that was called
constantly due probably to redraws of the Form. Therefore i can say that g.FillRectangle(x,y,w,h) is called.
But if i set x,y,width,heigth to say 80,20,20,20 respectively it is 20px in x and 89 px in y direction from the left-upper corner of the form ?
Is it Z-order of the rectangle i must set?
I think there is something wrong with how it draws..
Thanks
|
|
|
|
|
Hi again,
I solved it. It had to do with the offset for which a created the rectangle.. I tried som other numbers and it worked..
So now i can go on
Thanks all!
|
|
|
|
|
Hello All,
I am looking for an Design Pattern or Architectural design for the following (common) situation.
A Program that displays various 'Architectural Materials'(Paints, Wallcoverings, Carpet)
Each material has a few common properties (name, manufacturer, price etc)
Each 'subtype' has specific props (Paint=coverage & finish, Carpet=fiber & size)
What is the best way to deal with this in Objects, Database & GUI?
For Objects I could use a Decorator Pattern to make Paintable(material) or Wallcoverable(material)
Is that the best way to look at this?
For the db should I have a main Materials table then various PaintProps Table, CarpetProps table etc. (Rather then a Paints, Carpet table separately )
For the GUI I probably need a separate display form for each type of material (Paint, Carpet, Wallcovering) Is there a trick I need to know.
All input is greatly appreciated.
Thanks in advance
CM
|
|
|
|
|
I don't know how to use the operators DIV and MOD.
Help.
Vasildb
|
|
|
|
|
6 div 4 = 6 / 4
6 mod 4 = 6 % 4
|
|
|
|
|
Taking ejuanpp's answer one step further:
6 div 4 = 6 / 4 = 1
6 mod 4 = 6 % 4 = 2
/ravi
|
|
|
|
|
How to correct the date writen in textBox.
Example: If in the textBox i write 0 or number >31 it will falls.
What i have to do, but in textBox no in other like comboBox.
Help.
Vasildb
|
|
|
|
|
Hi,
you should create a function that checks wether a string is a valid date (or whatever).
Main point then is to call that function at the right time.
On every text change (as with TextChanged event, or KeyDown event) is often
not adequate, since partial dates (i.e. while entering characters in order to
construct a valid date) would be refused.
Better is to use an event that occurs when the dialog closes, but best of all
seems to use TextBox.LostFocus event, which occurs whenever something else gets
focus (e.g. a button, another textbox,...).
Luc Pattyn
|
|
|
|
|
or you can use Compare Validator to validate that the input is a valid date:
<asp:CompareValidator id="<SomeID>" runat="Server" Operator="DataTypeCheck"<br />
Type="Date" ErrorMessage="Please enter a valid date...."<br />
ControlToValidate="<Your TextBoxID>" />
|
|
|
|
|
Hi,
Assuming you are using an n-tier architecture for a windows application.
Let say you populate a dataGridView (in winform .net 2.0 control) from a dataSet. Then you make several changes (i.e. delete, update, insert, ...) to this dataSet in the control.
How can you then update the database with these changes. Should you use dataAdapter.Update(dataSet) in the datalayer or should you pass the dataset changes to the dataLayer and loop through each record in the dataset in a transaction and commit according to the changes i.e. .modified, added, deleted...
Thanks
|
|
|
|
|
Hi All,
I'm having an issue with constructors. I want to prevent the creation internally in the following example:
using System;<br />
<br />
public class ConditionalObject<br />
{<br />
private string _MajorName;<br />
private string _MinorName;<br />
public string MajorName { get { return _MajorName; } }<br />
public string MinorName { get { return _MinorName; } }<br />
public ConditionalObject()<br />
{<br />
if ((_MajorName.Length == 0) || (_MinorName.Length == 0))<br />
{<br />
throw new Exception("Unable to initialise new object without identifier.");<br />
<br />
}<br />
}<br />
public ConditionalObject(string AMajorName, string AMinorName): base()<br />
{<br />
_MajorName = AMajorName;<br />
_MinorName = AMinorName;<br />
}<br />
}
Neither Dispose(); nor return null; nor this = null; can be applied in constructor. Could anybody help me guys?
Thanks for the answers.
|
|
|
|
|
You can't prevent the object from being created, that is already done. When you throw an exception the object's reference won't be returned by the constructor, and the object will be left unreferenced in memory and eventually garbage collected.
---
It's amazing to see how much work some people will go through just to avoid a little bit of work.
|
|
|
|
|
Thanks Guffa. Unfortunatelly this is the main problem: it returns the (not null) object reference whatever I've thrown exception or not.
It is a quite big problem because I couldn't even check the previously unidentified object in the next line externally.
Is there any other way to solve this?
|
|
|
|
|
Tony Lambert wrote: Unfortunatelly this is the main problem: it returns the (not null) object reference whatever I've thrown exception or not.
So you just catch the exception and ignore it, or what?
---
It's amazing to see how much work some people will go through just to avoid a little bit of work.
|
|
|
|
|
I do nothing with it. (should I? ) I just throw it, it raises the exception message and the constructor returns with the object reference in the caller method instead of null.
Actually, this is the missing part of the puzzle: how to destroy or give null operand to the object in its constructor or mark it as destroyable or return with null?
|
|
|
|
|
Tony Lambert wrote: I just throw it, it raises the exception message and the constructor returns with the object reference in the caller method instead of null.
No, it doesn't. If you throw an exception in the constructor, the created object is never used. You don't get a reference to the object, as the reference is not assigned to any variable.
Tony Lambert wrote: Actually, this is the missing part of the puzzle: how to destroy or give null operand to the object in its constructor or mark it as destroyable or return with null?
You can't do that, and you don't need to, as the reference to the object will never be used. Just make sure that the object is left in a state so that it can be garbage collected.
---
It's amazing to see how much work some people will go through just to avoid a little bit of work.
|
|
|
|
|
I fail to see the use for a constructor that is not sufficient for instanciating your object. Why have the constructor there if it will make an object you deem invalid? Remove it and only accept calls to constructors that initialize the fields you need set.
-Larantz-
|
|
|
|
|
"Remove it and only accept calls to constructors that initialize the fields you need set."
Well it is okay in end user application, but it's an abstract class in library. Since it will be called by end-developers, the API must be consistent and any internal operation must to be transparent to make the library clear, and understandable.
|
|
|
|
|
Quote:
<code>
public class ConditionalObject
{
public ConditionalObject(string name)
{
try
{
if (name.Equals(""))
{
throw new ArgumentOutOfRangeException(this.ToString() +
": Unable to create new object without identifier.");
}
}
catch (ArgumentOutOfRangeException AException)
{
Console.WriteLine(AException.Message);
}
}
}
</code>
Your next example was according to what I meant. No empty constructors
-Larantz-
|
|
|
|
|
|
Thanks again. Here is a simple code:
using System;<br />
<br />
public class ConditionalObject<br />
{<br />
public ConditionalObject(string name)<br />
{<br />
try<br />
{<br />
if (name.Equals(""))<br />
{<br />
throw new ArgumentOutOfRangeException(this.ToString() +<br />
": Unable to create new object without identifier.");<br />
}<br />
}<br />
catch (ArgumentOutOfRangeException AException)<br />
{<br />
Console.WriteLine(AException.Message);<br />
}<br />
}<br />
}<br />
<br />
public class CallerClass<br />
{<br />
public static void Main()<br />
{<br />
ConditionalObject obj = new ConditionalObject("");<br />
Console.WriteLine(obj == null ? "null" : "not null");<br />
}<br />
}
When I change this:
ConditionalObject obj = new ConditionalObject("");
to this:
ConditionalObject obj = new ConditionalObject("anything");
the last line gives the same value (not null). What did I wrong?
|
|
|
|
|
Because you catch the exception inside the constructor, the constructor never exits with an exception.
---
It's amazing to see how much work some people will go through just to avoid a little bit of work.
|
|
|
|