|
nstk wrote: Or maybe it's the opposite that is true?
Yes. It is indeed the opposite that is true.
The sub class has access to all the protected members of the parent class but not the other way round.
Whenever we say we have a object deriving from something, we are always assuming that this object has properties of the parent and adds on some of its own.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
|
|
|
|
|
Hi,
is it possible use as argument of reused constructor something calculated in the constructor itself?
something like
Test(double b_):this(b_,c)
but where c comes from constructor itself. A simplified example:
lass Test
{
double area;
public Test(double b_)
{
double c = b_ * Math.Sqrt(44);
}
public Test(double b_ , double l)
{
area = b * l;
}
}
Thanks for your time
TheGermoz
|
|
|
|
|
Not like that, no. When you do something like:
Test(double b_):this(b_,c)
The underlying constructor (The two-arg one in this case) is executed BEFORE the current one, so it can't use variables that haven't been calculated yet.
You could use an initialization function, called from each constructor...
public Test(double b_)
{
double c_ = ...
Initialize(b_, c_);
}
public Test(double b_, double l)
{
Initialize(b_, l);
}
private void Initialize(double b_, double l)
{
...
}
|
|
|
|
|
thanks a lot very clear answer
|
|
|
|
|
Or maybe Test(double b_):this(b_,b_ * Math.Sqrt(44)) ?
|
|
|
|
|
ok but in my specific case
// here do some operation with b, to obtain c.
so to get c from d I need many lines of code...
unfortunately I can not use your good hint
Thanks a lot anyway..
|
|
|
|
|
You can put expressions in the call to the base constructor, including calls to other classes and to static methods. In your case, the expression is simple, so you can do
public Test(double b) : this(b, b * Math.Sqrt(44)) { ...
... although that number should really be a declared constant (not sure if the compiler is clever enough to work out that it's constant).
You can't call any instance methods, because none of your constructor code has run yet and so the object is not in a valid state. You should never need to do that, as the constructor parameters (which you can pass to a static method) by definition completely define the state of the new object.
Be careful doing this, as it can lead to unwieldy code quite easily. Generally, putting a lot of logic in constructors is a symptom of a higher level design problem – it should usually be moved into initialisation methods or to where it is actually needed.
|
|
|
|
|
I have the following code to draw a grid based on the size, width and height of a map:
public void DrawCollisionMap(Map map)
{
_panel.AutoScrollMinSize = new Size(map.Width*Map.TileSize, map.Height*Map.TileSize);
_panel.Paint -= _panel_Paint;
_panel.Paint += _panel_Paint;
_panel.Invalidate(true);
}
void _panel_Paint(object sender, PaintEventArgs e)
{
e.Graphics.Clear(Color.White);
for (int x = 0; x < _map.Width; x++)
{
for (int y = 0; y < _map.Height; y++)
{
e.Graphics.DrawRectangle(_pen, x * Map.TileSize, y * Map.TileSize, _map.Width, _map.Height);
}
}
}
The problem is that when it is rendered the grid does not render correctly:
http://imageshack.us/photo/my-images/864/gridr.jpg/[^]
I do not understand
|
|
|
|
|
venomation wrote: I do not understand
Man, are you happy or sad now?
venomation wrote: The problem is that when it is rendered the grid does not render correctly
What do you mean? what's your expected output?
|
|
|
|
|
venomation wrote: I do not understand
I do. I read your code and saw the mistake right away.
However I'm not going to tell you what it is, I just give you some advice: when something does not behave as expected, trim it down to a fraction of what you intend to have, and check that first.
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Please use <PRE> tags for code snippets, they improve readability. CP Vanity has been updated to V2.3
|
|
|
|
|
Aha how silly of me !
Apart from being silly the other reason why I didn't notice the maps dimensions instead of the tile-size is that I got it working on DirectX so "thought" I knew what I was doing ^^.
Thanks for making me see the light
|
|
|
|
|
We're not done yet. I have two comments on your code:
1.
the remove-then-add-a-handler stuff looks unnecessary. Why are you doing this?
2.
once you fixed the error, you are drawing a large number of tiny adjacent rectangles, which means a lot of computational effort, and also each tiny edge gets drawn twice. And all you really need for a grid of N by N cells, is N+1 horizontal lines and N+1 vertical lines. That does not take more code, it does not have nested for loops, and even may be less error prone!
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Please use <PRE> tags for code snippets, they improve readability. CP Vanity has been updated to V2.3
|
|
|
|
|
The event handling is terrible I know, only there for a quick hack as I wanted to fix the old issue...
The cells need to be "cell by cell" instead of lines as the user will change them (tile map style).
I don't know if your suggestion would help for that, I made a slight improvement in the loop by calculating the difference before:
for (int x = dbPanel1.HorizontalScroll.Value%size; x < width*size; x+= size)
{
for (int y = dbPanel1.VerticalScroll.Value % size; y < height * size; y += size)
{
e.Graphics.DrawRectangle(_p, x , y , size, size);
}
}
|
|
|
|
|
Yes, the readability has increased a lot.
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Please use <PRE> tags for code snippets, they improve readability. CP Vanity has been updated to V2.3
|
|
|
|
|
Some more comments, out of the blue:
1. if you create instances of a class that has a Dispose() method(such as Graphics, Font, Pen, Brush), you should call it when done with the objects.
2. you should avoid creating objects inside an event handler that is going to be called often; say you need a few brushes, just create them once and keep them around.
3. There are a whole lot of stock objects available at no extra charge, see classes such as Pens and Brushes . (and no, you don't dispose them, they aren't yours, you just borrow them).
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Please use <PRE> tags for code snippets, they improve readability. CP Vanity has been updated to V2.3
|
|
|
|
|
Hi,
RegistryKey.openSubKey("KeyName",true) working in windows XP , but it is not working in
Windows 7 32 bit. we are getting error : no rights to read.Please suggest me better way
|
|
|
|
|
I have just tested it with Win 7 from the MSDN example, and it is working fine. The MSDN site recommends using
Registry.CurrentUser.OpenSubKey("yourKeyName", true); maybe that is an issue.
...and I have extensive experience writing computer code, including OIC, BTW, BRB, IMHO, LMAO, ROFL, TTYL.....
|
|
|
|
|
Windows, since Vista, protects those entries that affect all users, so you can't just access some of the hives (e.g. LOCAL_MACHINE) any more, unless you get the required privileges and go through UAC. I don't have all the details, I suggest you Google. The CURRENT_USER hive works just fine.
And the way the protection works is different on 64-bit systems, I haven't figured that one out at all.
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Please use <PRE> tags for code snippets, they improve readability. CP Vanity has been updated to V2.3
|
|
|
|
|
Luc Pattyn wrote: The CURRENT_USER hive works just fine.
Unless you're running an app over the network on a terminal and/or VPN.
At least, it wouldn't the current user access the HKCU hive when remoting in on the systems here.
|
|
|
|
|
hi
is there any way to make Silent installation to my C# program - on Visual-Studio 2008
(i mean that i dont want that when the user install my program he will need to press next->next...)
thanks in advance
|
|
|
|
|
Do you need an installation at all?
if the right version of .NET is present, and your app doesn't need "all user" access in the registry and/or in the file system, then chances are copying its files (exe, dll's, config) to some folder on the local disk is all it takes to make it executable.
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Please use <PRE> tags for code snippets, they improve readability. CP Vanity has been updated to V2.3
|
|
|
|
|
Or you can just make a normal .MSI install and install it with
msiexec /i myinstaller.msi /qn
|
|
|
|
|
Hi
I am using OleDbDataAdapter to read an excel file from harddisk. Like
using (OleDbConnection conn = new OleDbConnection(strConnectionString))
{
conn.Open();
using (OleDbCommand cmd = conn.CreateCommand())
{
cmd.CommandText ="SELECT [ATA], [SID], [Equipment] FROM [Sheet$] ;
try
{
using (OleDbDataReader reader = cmd.ExecuteReader())
{
FieldInfo fi;
bool bsave = true;
while (reader.Read())
{
...
}
But the names of columns are in the second row.
How can i write that query.
excel sample data how it looks ( see picture with this message )
http://imageshack.us/photo/my-images/96/excelo.png/[^]
Please help
With regards
|
|
|
|
|
I copy and paste only the part of the sheet I need to another sheet and use that. This also allows me to clean up the data a bit first without altering the original sheet.
|
|
|
|
|
Good idea, can you give me some lines of codes or something to help ?
|
|
|
|