|
Time to understand the difference between overloading and overriding. Method overload resolution happens at compile time, so the compiler sees that you call Move with an instance of Animal and that there is no method that takes it as a parameter. Virtual method dispatch, which you can achieve by declaring Move virtual or abstract, happens at run time, based on the runtime type of the object returned by GetAnimal. Because the compiler cannot possibly figure the actual type of the object returned by GetAnimal, it can only assume what you've declared i.e it returns Animal.
So no, you cannot do what you want using overloading, unless you return explicit types (GetCat(), GetDog(), for eg.).
Regards
Senthil
_____________________________
My Blog | My Articles | My Flickr | WinMacro
|
|
|
|
|
Thanks for the answer.
I decided to go with the abstract solution as i could probably come in handy later on.
I guess it would have worked if i used the ArrayList with the objects directly and just did something like
Move(theArrayList[index]); -- hmm i am sure i once found an articel on this site about this ... hmm
Best regards
Martin ...
-- modified at 22:16 Tuesday 11th April, 2006
|
|
|
|
|
Hi,
Please see the following code below:
//////////////////////////////////////////////
.....
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
xOrigin = Form1.ActiveForm.ClientRectangle.Width/2;
yOrigin = Form1.ActiveForm.ClientRectangle.Height/2;
DrawThisLine(e.Graphics);
}
public void DrawThisLine(Graphics g)
{
Pen pen = new Pen(Color.Black, 3);
g.DrawLine(pen, xOrigin, yOrigin, xOrigin + 75, yOrigin + 75);
}
private void timer1_Tick(object sender, System.EventArgs e)
{
}
....
///////////////////////////////////////////
I have tried to use the timer1 object and the timer1 event but can't seem to get the line to move around on the Form1. Ultimately I'd like it to rotate around like a clock hand but at this point I'll take any code fragment just to get it in some sort of animated motion.
Thanks a lot in advance....
|
|
|
|
|
Well, as you are not doing anything in the timer event, you can't expect much to happen.
Do some changes to what you are drawing, and cause a redraw:
something += whatever;<br />
this.Invalidate();
You might want to do the drawing on something like a panel, though, so you don't have to redraw the entire window for every update.
---
b { font-weight: normal; }
|
|
|
|
|
THanks,
I intentionally left them blank.
I think my main confusion is the fact that I have to do all the drawing in the paint handler. Once i added the timer event I can't figure out how to tie the the paint event to the timer and the function that draws the line in the paint event.
|
|
|
|
|
That's what the Invalidate call is for. It causes a repaint.
---
b { font-weight: normal; }
|
|
|
|
|
This is my problem, it seems pretty tough.
I have an XML file that is structured like this
<code>
papers
--paper
----id
----title
----tracks
-------track
-------track
-------track
--paper /
--paper
.
.
.
papers /
</code>
SO basically a bunch of paper nodes, each with a track node that has multimpe track chrildren.
So display this data on my page using a repeater
<pre> <asp:repeater id="RepeaterReviewers" runat="server">
<ItemTemplate>
<div class="reviewerListItem">
<div>
<span class="bold"><%# Container.ItemIndex + 1%> </span><%# XPath ("name") %>
(<a href='mailto:<%# XPath ("email") %>'><%# XPath ("email") %></a>)
</div>
<div>
<%# XPath ("affiliation") %>
-
<%# XPath ("country") %>
</div>
<div>
<span>Tracks: <%# XPath ("tracks") %> </span>
</div>
<div><span>
Currently Reviewing: </span><span class="bold"> <%# XPath ("count(papers/id)") %></span>
</div>
</div>
</ItemTemplate>
</asp:repeater> </pre>
but my problem is, I only know how to get back one node using <code><%# XPath ("tracks") %></code> using this syntax. How can I get the value of track nodes inside of tracks????. Remember, I am using a repeater...
/\ |_ E X E GG
-- modified at 16:02 Sunday 9th April, 2006
|
|
|
|
|
How to do it? I need to do some code after any application is started.
For example, I have Win Service and want to write in DataBase any starting application!
|
|
|
|
|
Hi, I am trying to get the color of particular pixel of a panel object, or Graphicx object... can you help me urgently
thanks
|
|
|
|
|
The solution is here:
http://www.gotdotnet.com/Community/MessageBoard/Thread.aspx?id=330183[^]
I've put it in a helperclass so it's easier to use it:
public class PixelGetterHelperclass
{
[DllImport("gdi32.dll")]
private static extern uint GetPixel(IntPtr hDC, int XPos, int YPos);
[DllImport("gdi32.dll")]
private static extern IntPtr CreateDC(string driverName, string deviceName, string output, IntPtr lpinitData);
[DllImport("gdi32.dll")]
private static extern bool DeleteDC(IntPtr DC);
private static byte GetRValue(uint color)
{
return (byte)color;
}
private static byte GetGValue(uint color)
{
return ((byte)(((short)(color)) >> 8));
}
private static byte GetBValue(uint color)
{
return ((byte)((color)>>16));
}
private static byte GetAValue(uint color)
{
return ((byte)((color)>>24));
}
public static Color GetColorFromPoint(Point p)
{
IntPtr displayDC = CreateDC("DISPLAY", null, null, IntPtr.Zero);
uint colorref = GetPixel(displayDC, p.X, p.Y);
DeleteDC(displayDC);
return Color.FromArgb(
GetRValue(colorref),
GetGValue(colorref),
GetBValue(colorref));
}
} I've made a codesample for you to download here: http://sweetsilence.dk/codeprojectprojects/CodeProjectSample_ColorOfParticularPixel/CodeProjectSample_ColorOfParticularPixel.zip[^]
Kind regards - Jakob
Three kinds of people in the world:
- Those who can count..
- Those who can't!
|
|
|
|
|
But what if there is a window over the panel or form at X,Y what color would it return is it the color of the panel or the window over the panel. I tried the same thing before and the results were not as expected. It always returned the color of the top most form, thus to ensure that u get the correct color may be set the TopMost property of the Form TRUE; this is not the best way to do it but u prevent it from getting the color of unwanted windows.
|
|
|
|
|
I don't think there is way to get this working in general, because it interferes with how the Graphics class works. It is merely a wrapper around a target handling graphical input. This could be a bitmap, a panel (like in your case), a printer and much more. As you can image it would be near to impossible to get a pixel color from a graphics which sends all its input to a printer.
Please explain a little more what you are trying to do. Probably there is another way to achieve it. For example I could assume that the Pnael is self drawn by you. If yes than you should double buffer the painting into a bitmap and in the end paint that bitmap onto the panel. Then you could use the buffered bitmap to receive your color (and moreover only regenerate the bitmap when you now the panel has changed).
|
|
|
|
|
f(extract){
//Read the length of the hidden message from the first pixel
pixelColor = bitmap.GetPixel(0,0);
messageLength = (pixelColor.R << 2) + (pixelColor.G << 1) + pixelColor.B;
messageStream = new MemoryStream(messageLength);
}else{
messageLength = (Int32)messageStream.Length;
What is the function of (pixelColor.R << 2) + (pixelColor.G << 1) + pixelColor.B; ????? What is happening in this line ??
AMAN ANWAR
|
|
|
|
|
nwr_mn wrote: What is the function of (pixelColor.R << 2) + (pixelColor.G << 1) + pixelColor.B; ????? What is happening in this line ?
It's just some basic bitshifting to the left
R,G,B are bits like that:
01010110. << 2 will shift this 2 times to the left: 01011000
<< 1 is the same as value*2
<< 2 therefore value*2*2
But this can get risky when you shift a "1" out of the bit range, you end up with a different value then.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
PLZ help me out in Steganogarphy in Bitmaps ............. i am not able to understand how to use the Keystream And the Message Stream >>>>>>
AMAN ANWAR
|
|
|
|
|
There are a lot of articles on this website about this subject. Just go to the search box on the top left corner of this webpage, enter "Steganography", and click enter. I found over 10 articles on the first shot.
|
|
|
|
|
CAN ANY one Help me out with Steganography In C#. it's Urgent ........
AMAN ANWAR
|
|
|
|
|
nwr_mn wrote: it's Urgent ........
What's the hurry? Most of us on CP are not in a hurry. Have you tried google.com[^]?
|
|
|
|
|
public class CryptUtility {
/// Hides a message in a bitmap
/// <param name="messageStream" />The message to hide
/// <param name="bitmap" />The carrier bitmap
/// <param name="keyStream" />The key to use
public static void HideMessageInBitmap(Stream messageStream, Bitmap bitmap, Stream keyStream, bool useGrayscale){
HideOrExtract(ref messageStream, bitmap, keyStream, false, useGrayscale);
messageStream = null;
}
/// Extracts an hidden message from a bitmap
/// <param name="bitmap" />The carrier bitmap
/// <param name="keyStream" />The key used for hiding the message
/// <param name="messageStream" />Empty stream to receive the message
public static void ExtractMessageFromBitmap(Bitmap bitmap, Stream keyStream, ref Stream messageStream){
HideOrExtract(ref messageStream, bitmap, keyStream, true, false);
}
/// Stepts through the pixels of a bitmap using a key pattern and hides or extracts a message
/// <param name="messageStream" />If exctract is false, the message to hide - otherwise an empty stream to receive the extracted message
/// <param name="bitmap" />The carrier bitmap
/// <param name="keyStream" />The key specifying the unchanged pixels between two hidden bytes
/// <param name="extract" />Extract a hidden message (true), or hide a message in a clean carrier bitmap (false)
private static void HideOrExtract(ref Stream messageStream, Bitmap bitmap, Stream keyStream, bool extract, bool useGrayscale){
//Current count of pixels between two hidden message-bytes
//Changes with every hidden byte according to the key
int currentStepWidth = 0;
//Current byte in the key stream - normal direction
byte currentKeyByte;
//Current byte in the key stream - reverse direction
byte currentReverseKeyByte;
//current position in the key stream
long keyPosition;
//maximum X and Y position
int bitmapWidth = bitmap.Width-1;
int bitmapHeight = bitmap.Height-1;
//Color component to hide the next byte in (0-R, 1-G, 2-B)
//Rotates with every hidden byte
int currentColorComponent = 0;
//Stores the color of a pixel
Color pixelColor;
//Length of the message
Int32 messageLength;
if(extract){
//Read the length of the hidden message from the first pixel
pixelColor = bitmap.GetPixel(0,0);
messageLength = (pixelColor.R << 2) + (pixelColor.G << 1) + pixelColor.B;
messageStream = new MemoryStream(messageLength);
}else{
messageLength = (Int32)messageStream.Length;
if(messageStream.Length >= 16777215){ //The message is too long
String exceptionMessage = "The message is too long, only 16777215 bytes are allowed.";
throw new Exception(exceptionMessage);
}
//Check size of the carrier image
//Pixels available
long countPixels = (bitmapWidth*bitmapHeight) -1;
//Pixels required - start with one pixel for length of message
long countRequiredPixels = 1;
//add up the gaps between used pixels (sum up all the bytes of the key)
while((keyStream.Position < keyStream.Length)&&(keyStream.Position < messageLength)){
countRequiredPixels += keyStream.ReadByte();
}
//If the key is shorter than the message, it will be repeated again and again
//Multiply with count of key periods
countRequiredPixels *= (long)System.Math.Ceiling( ((float)messageStream.Length / (float)keyStream.Length) );
if(countRequiredPixels > countPixels){ //The bitmap is too small
String exceptionMessage = "The image is too small for this message and key. "+countRequiredPixels+" pixels are required.";
throw new Exception(exceptionMessage);
}
//Write length of the bitmap into the first pixel
int colorValue = messageLength;
int red = colorValue >> 2;
colorValue -= red << 2;
int green = colorValue >> 1;
int blue = colorValue - (green << 1);
pixelColor = Color.FromArgb(red, green, blue);
bitmap.SetPixel(0,0, pixelColor);
}
//Reset the streams
keyStream.Seek(0, SeekOrigin.Begin);
messageStream.Seek(0, SeekOrigin.Begin);
//Current position in the carrier bitmap
//Start with 1, because (0,0) contains the message's length
Point pixelPosition = new Point(1,0);
//Loop over the message and hide each byte
for(int messageIndex=0; messageIndex<messagelength; messageindex++){
=""
="" repeat="" the="" key,="" if="" it="" is="" shorter="" than="" message
="" if(keystream.position="=" keystream.length){
="" keystream.seek(0,="" seekorigin.begin);
="" }
="" get="" next="" pixel-count="" from="" use="" "1"="" it's="" 0
="" currentkeybyte="(byte)keyStream.ReadByte();
" currentstepwidth="(currentKeyByte==0)" ?="" (byte)1="" :="" currentkeybyte;
="" jump="" to="" reverse-read="" position="" and="" read="" end="" of="" stream
="" keyposition="keyStream.Position;
" keystream.seek(-keyposition,="" seekorigin.end);
="" currentreversekeybyte="(byte)keyStream.ReadByte();
" back="" normal="" position
="" keystream.seek(keyposition,="" perform="" line="" breaks,="" current="" step="" wider="" image
="" while(currentstepwidth=""> bitmapWidth){
currentStepWidth -= bitmapWidth;
pixelPosition.Y++;
}
//Move X-position
if((bitmapWidth - pixelPosition.X) < currentStepWidth){
pixelPosition.X = currentStepWidth - (bitmapWidth - pixelPosition.X);
pixelPosition.Y++;
}else{
pixelPosition.X += currentStepWidth;
}
//Get color of the "clean" pixel
pixelColor = bitmap.GetPixel(pixelPosition.X, pixelPosition.Y);
if(extract){
//Extract the hidden message-byte from the color
byte foundByte = (byte)(currentReverseKeyByte ^ GetColorComponent(pixelColor, currentColorComponent));
messageStream.WriteByte(foundByte);
//Rotate color components
currentColorComponent = (currentColorComponent==2) ? 0 : (currentColorComponent+1);
}else{
//To add a bit of confusion, xor the byte with a byte read from the keyStream
int currentByte = messageStream.ReadByte() ^ currentReverseKeyByte;
if(useGrayscale){
pixelColor = Color.FromArgb(currentByte, currentByte, currentByte);
}else{
//Change one component of the color to the message-byte
SetColorComponent(ref pixelColor, currentColorComponent, currentByte);
//Rotate color components
currentColorComponent = (currentColorComponent==2) ? 0 : (currentColorComponent+1);
}
bitmap.SetPixel(pixelPosition.X, pixelPosition.Y, pixelColor);
}
}
//the stream will be closed by the calling method
bitmap = null;
keyStream = null;
}
/// Return one component of a color
/// <param name="pixelColor" />The Color
/// <param name="colorComponent" />The component to return (0-R, 1-G, 2-B)
/// <returns>The requested component
private static byte GetColorComponent(Color pixelColor, int colorComponent){
byte returnValue = 0;
switch(colorComponent){
case 0:
returnValue = pixelColor.R;
break;
case 1:
returnValue = pixelColor.G;
break;
case 2:
returnValue = pixelColor.B;
break;
}
return returnValue;
}
/// Changees one component of a color
/// <param name="pixelColor" />The Color
/// <param name="colorComponent" />The component to change (0-R, 1-G, 2-B)
/// <param name="newValue" />New value of the component
private static void SetColorComponent(ref Color pixelColor, int colorComponent, int newValue){
switch(colorComponent){
case 0:
pixelColor = Color.FromArgb(newValue, pixelColor.G, pixelColor.B);
break;
case 1:
pixelColor = Color.FromArgb(pixelColor.R, newValue, pixelColor.B);
break;
case 2:
pixelColor = Color.FromArgb(pixelColor.R, pixelColor.G, newValue);
break;
}
}
private static String UnTrimColorString(String color, int desiredLength){
int difference = desiredLength - color.Length;
if(difference > 0){
color = new String('0', difference) + color;
}
return color;
}
}
}
AMAN ANWAR
|
|
|
|
|
|
Selecting a tab in a tabcontrol leaves a selection outline around the tab name. I'm currently using a Event to shift the focus to a control on the tab but it still flashed the selection outline. I've also looked at the control ShowFocusCues property but it's read only. Is there an easy way to remove this behaviour using C#?
// Mikzi L. Freeman
|
|
|
|
|
Hi,
I want 2 use KeyEventHandler in a form but when i use this statement no event happen
this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.Form1_KeyPress);
and
private void Form1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)<br />
{<br />
Lbl1.Text = ((System.Windows.Forms.Key) Sender).ToString();<br />
}
plz help me.
---------------------
Areff Bahrami(KAVEH)
Areff.HB@Gmail.com
---------------------
|
|
|
|
|
Have you tried setting the form's KeyPreview property to true?
Kind regards - Jakob
Three kinds of people in the world:
- Those who can count..
- Those who can't!
|
|
|
|
|
I think you may have confused what is passed in through 'sender'. In this situation sender returns a reference to the control which received the key press. If you want to access the key which was sent, you can use e.KeyChar
Graham
|
|
|
|
|
Hi,
I have tow form in my application and one button in Form1,
i want when button clicked Form2 be Show and Form1 be hide or UnActivate
---------------------
Areff Bahrami(KAVEH)
Areff.HB@Gmail.com
---------------------
|
|
|
|
|