|
Ping.SendAsync[^] does an asynchronous ping, sounds like that's what you're looking for
|
|
|
|
|
In a comboBox as you move the mouse across the list of items, the item under the mouse is highlighted (without clicking on it). How do you make a list box work the same way? Currently I display a different picture for each item in the listbox as the mouse moves over it, but without it higlighting as I move over it, it is sometimes difficult to tell which item I am drawing for. I have search the internet and several books for this but have not found anything related to this topic.
Gary
|
|
|
|
|
The simplest way to achieve this is to get the index of the item that is below the mouse using the IndexFromPoint and select this item:
private void listTest_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
int index = listTest.IndexFromPoint(e.X, e.Y);
listTest.SelectedIndex = index;
}
Regards
Nuri
|
|
|
|
|
I knew there had to be a simple way to do it, and after seeing this I feel embrassed that I didn't think to try that myself. Thank you very much.
Gary
|
|
|
|
|
Hi. I'm now using the SortedList<TKey, TValue> to sort the strings from the text file. Is it possible to have a single key as the basis for comparing each string? If yes, I want to know how i will prevent the key from duplicating. Can someone help me?
As of now this is what I accomplished:
public static void SortByLastName(ref string[] arrayOfLastNames, ref string[] arrayOfFirstNames, ref string[] arrayOfPlateNum, ref string[] arrayOfType, ref string[] arrayOfYear)
{
Console.Clear();
int vehicleCountInt = 0;
Console.WriteLine("SHOW DATABASE: SORTING BY LAST NAME\n");
using (StreamReader countVehicle = new StreamReader("vehiclecount.txt"))
{
vehicleCountInt = Int32.Parse(countVehicle.ReadLine());
countVehicle.Close();
}
SortedList<string, string> sortedLastName = new SortedList<string, string>(vehicleCountInt);
using (StreamReader outputLastNames = new StreamReader("lastnames.txt"))
{
for (int i = 0; i < vehicleCountInt; i++)
{
arrayOfLastNames[i] = outputLastNames.ReadLine();
string keyVal = arrayOfLastNames[i];
sortedLastName.Add(keyVal, arrayOfLastNames[i]);
if (!sortedLastName.ContainsKey(keyVal))
{
sortedLastName.Add(keyVal, arrayOfLastNames[i]);
}
else
{
sortedLastName.Remove(keyVal);
sortedLastName.Add(keyVal, arrayOfLastNames[i]);
}
Console.WriteLine("{0}", sortedLastName.Keys[i]);
}
outputLastNames.Close();
}
}
modified on Friday, September 4, 2009 11:47 AM
|
|
|
|
|
gamer1127 wrote: sortedLastName.Add(keyVal, arrayOfLastNames[i]); //I'm having a run-time error here that throws the ArgumentException
What information does the debugger show? The ArgumenException implies that one of the arguments to the sortedLastName.Add() call contains an invalid value, quite possibly null.
|
|
|
|
|
It says that an entry with the same key already exists.
|
|
|
|
|
gamer1127 wrote: sortedLastName.Add(keyVal, arrayOfLastNames[i]); //I'm having a run-time error here that throws the ArgumentException
if (!sortedLastName.ContainsKey(keyVal))
{
sortedLastName.Add(keyVal, arrayOfLastNames[i]);
}
else
{
sortedLastName.Remove(keyVal);
sortedLastName.Add(keyVal, arrayOfLastNames[i]);
}
You did it wrong, then you did it right. Why do you even have the line that is getting the error? You are doing the same thing with the next if block.
gamer1127 wrote: Console.WriteLine("{0}", sortedLastName.Keys[i]);//And sometimes throws the exception ArgumentOutOfRange Exception
You are getting this error for the same reason you were getting the previous error. If you have a duplicate key, you will not have "i" items in the list. You need to check if that many keys exist before trying to write them out.
On an style note, it appears that you have several properties of items all stored in separate arrays, and a single array of a class (with FirstName, LastName, PlateNumber, Type, and Year properties) may be better. Also, there is no reason to pass the array by ref just to change the values in them. If you are passing the array by ref so you can change the length, I would suggest returning an array instead, since you do not seem to be using the data already in the arrays.
|
|
|
|
|
Gideon Engelberth wrote: On an style note, it appears that you have several properties of items all stored in separate arrays, and a single array of a class (with FirstName, LastName, PlateNumber, Type, and Year properties) may be better.
Can you please show an example for that?
By the way, I already solved the problems. I'll get back to you guys when a new problem comes up.
|
|
|
|
|
What if there are values that are the same? How will I show those two? I know that they must have different keys but how will I exactly do that?
For example:
Hibaler
Balde
Metin
Dela Vega
Dimagiba
Pederoso
Dinulos
Du
Gotengco
Lira
Guban
Garraez
Carpena
Reyes
Zulueta
Gonzalez
Isidoro
Marfa
Reyes
Guinhawa
Aaron
Lazaro
Obsum
Molino
Estenor
Nolasco
Paral
Porillo
Novillos
Alihan
How will I assign different values for the other so i can show them both after sorting?
|
|
|
|
|
why are you making everything much more complex than necessary?
dictionaries (SortedList is a dictionary) require keys to be unique, which does not match your application; so forget about dictionaries as your primary storage.
you can keep a list of strings (any strings including duplicates) in a List<string> which you can simply sort by calling myList.Sort()
you can also define your own little class "MyType" (holding name, age, address, vehicleColor, whatever) and collect those in a List<MyType>
Strings get sorted alphabetically by default; your own objects don't have a default sort order. If you need a (special) sort order (i.e. non-alphabetic for strings) you can easily do that with an object that implements IComparable; I wrote a little article[^] that explains it all.
FWIW: I strongly recommend you buy and study a book on C# to increase your basic knowledge of the language and the .NET framework. Here[^] is why.
|
|
|
|
|
Luc Pattyn wrote: why are you making everything much more complex than necessary?
My answer to that is because the program that i'm creating is for the subject that i have about data structures. I can't use Array.Sort() etc because the solution that we presented is to use radix sort(which i didn't continue because I can't resolve the error i always get). We have a different subject for the fundamentals and other things about C#.
But I'll take your advice. I already visited the links that you posted and read it especially about learning a new language. I already have a book, the title: C# Programming: From Program Analysis to Program Design by Barbara Doyle. But probably I'll do what you said there so I can have more knowledge about the language.
|
|
|
|
|
OK
Now SortedList is not dealing with duplicate keys and not doing Radix Sort, so it is a bad choice.
What you need is create your own collection class, probably inheriting from List<string> or List<MyType>, start by using its normal Sort method, later on override the Sort method with your own (for which I already gave the basic principles in another thread).
|
|
|
|
|
Hi,
I have a Form called from another Form. I've put events in both forms. The called forms mouse events aren't being triggered. The OnClosing event is triggered. Any and all help appreciated!
Please note: the events that only have a Console.Writeln in them are for debug purposes only.
Non-working code follows:
using DataObject;
using SvgNet;
using SvgNet.SvgElements;
using SvgNet.SvgTypes;
using System;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;
using System.Collections.Generic;
namespace PiPe
{
/// <summary>
/// Summary description for ImageRevealViewer.
/// </summary>
public class ImageRevealViewer : Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private Container components = null;
private SubObjectCollection items = new SubObjectCollection();
private SubObject selecteditem;
private List<ImageRevealBox> iRBoxes;
private ImageRevealBox imageItem;
private ImageRevealLink iRLink;
private Catalogue Catalogue;
private Panel imageBox;
private GroupBox imageDisplayer;
private Point offset = new Point();
private Point negOffset;
private UserControl parent; // the calling object
private int maximum;
private NewPToolTip toolTip = new NewPToolTip();
private SubObject imageObject;
private SubObject citem = new MailToLink();
private bool toolTipShown;
private bool parentIsCanvas;
private int originalClientHeight;
private int originalClientWidth;
/// <summary>
/// To show one ImageRevealBox.
/// </summary>
/// <param name="iRLink">An ImageRevealLink</param>
/// <param name="catalogue">The parent catalogue we are using</param>
/// <param name="offset">An offset. All start and end locations will be displaced by this offest</param>
public ImageRevealViewer(ImageRevealLink aLink, Catalogue cat, Point os, Canvas uC)
{
InitializeComponent();
iRLink = aLink;
items.Add(iRLink);
parent = uC;
imageItem = iRLink.ImageRevealItems[0];
iRBoxes = new List<ImageRevealBox>(iRLink.ImageRevealItems.Count);
iRBoxes.AddRange(iRLink.ImageRevealItems);
this.Catalogue = cat;
this.StartPosition = FormStartPosition.Manual;
MaximumLength = 1;
offset = os;
negOffset = new Point(0 - offset.X, 0 - offset.Y);
parentIsCanvas = true;
drawObject(MOTION.NONE);
}
// Currently we allow only one image. We may allow more in the future
private struct MOTION
{
public const int NONE = 0;
//public const int FORWARD = 1;
//public const int BACK = 2;
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.imageBox = new System.Windows.Forms.Panel();
this.imageDisplayer = new System.Windows.Forms.GroupBox();
this.imageDisplayer.SuspendLayout();
this.SuspendLayout();
//
// imageBox
//
this.imageBox.Location = new System.Drawing.Point(0, 0);
this.imageBox.Margin = new System.Windows.Forms.Padding(0);
this.imageBox.Name = "imageBox";
this.imageBox.Size = new System.Drawing.Size(800, 600);
this.imageBox.TabIndex = 1;
this.imageBox.Paint += new System.Windows.Forms.PaintEventHandler(this.imageBox_Paint);
this.imageBox.Invalidated += new System.Windows.Forms.InvalidateEventHandler(this.imageBox_Invalidated);
//
// imageDisplayer
//
this.imageDisplayer.Controls.Add(this.imageBox);
this.imageDisplayer.Location = new System.Drawing.Point(0, 0);
this.imageDisplayer.Margin = new System.Windows.Forms.Padding(0);
this.imageDisplayer.Name = "imageDisplayer";
this.imageDisplayer.Padding = new System.Windows.Forms.Padding(0);
this.imageDisplayer.Size = new System.Drawing.Size(800, 600);
this.imageDisplayer.TabIndex = 15;
this.imageDisplayer.TabStop = false;
//
// ImageRevealViewer
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
this.ClientSize = new System.Drawing.Size(800, 600);
this.Controls.Add(this.imageDisplayer);
this.DoubleBuffered = true;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "ImageRevealViewer";
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
this.TransparencyKey = System.Drawing.SystemColors.Control;
this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.ImageRevealViewer_MouseUp);
this.MouseClick += new System.Windows.Forms.MouseEventHandler(this.ImageRevealViewer_MouseClick);
this.MouseCaptureChanged += new System.EventHandler(this.ImageRevealViewer_MouseCaptureChanged);
this.MouseEnter += new System.EventHandler(this.ImageRevealViewer_MouseEnter);
this.Leave += new System.EventHandler(this.ImageRevealViewer_Leave);
this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.ImageRevealViewer_MouseDown);
this.MouseLeave += new System.EventHandler(this.ImageRevealViewer_MouseLeave);
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.OnClosing);
this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.OnMouseMove);
this.MouseHover += new System.EventHandler(this.ImageRevealViewer_MouseHover);
this.imageDisplayer.ResumeLayout(false);
this.ResumeLayout(false);
}
void imageBox_Invalidated(object sender, InvalidateEventArgs e)
{
}
void imageBox_Paint(object sender, PaintEventArgs e)
{
Console.WriteLine("imageBox_Paint");
if (imageObject != null)
{
Graphics g = imageBox.CreateGraphics();
imageObject.Draw(g);
}
}
#endregion
// Currently we only allow one image for Image Reveal. In the future we may allow more...
private void ImageSelect(int direction)
{
//if(direction == MOTION.FORWARD) // go to next image
//{
// if(this.current != this.maximum) this.current++;
//}
//else // go to previous image
//{
// if(this.current!=0) this.current--;
//}
//current = 0;
}// end ImageSelect
/// <summary>
/// This method draws a new image. This method is called by either
/// clicking up or clicking down in the slide show viewer.
///
/// This method calls ImageSelect(bool svg, bool forward).
/// </summary>
/// <param name="forward"></param>
private void drawObject(int direction)
{//begin method
imageBox.Paint -= new PaintEventHandler(imageBox_Paint);
Point newStartLocation = imageItem.StartLocation;
newStartLocation.Offset(offset);
calcClientHeightWidth();
imageBox.Size = imageItem.StartSize;
this.Location = newStartLocation;
this.imageBox.Refresh();
Graphics g = this.imageBox.CreateGraphics();
SubObject so = imageItem as SubObject;
so.Draw(g);
imageObject = so;
imageBox.Paint += new PaintEventHandler(imageBox_Paint);
}// end method
private void calcClientHeightWidth()
{
int pHeight = 0;
int pWidth = 0;
int dispHeight;
int dispWidth;
originalClientHeight = imageItem.ClientHeight;
originalClientWidth = imageItem.ClientWidth;
if (parentIsCanvas)
{
pHeight = (parent as Canvas).Height;
pWidth = (parent as Canvas).Width;
}
dispHeight = imageItem.StartLocation.Y + pHeight;
dispWidth = imageItem.StartLocation.X + pWidth;
if (imageItem.ClientHeight > dispHeight &&
imageItem.ClientWidth > dispWidth)
{
Size dispSize = new Size(dispWidth, dispHeight);
imageDisplayer.Size = dispSize;
this.Size = dispSize;
imageItem.ClientHeight = dispHeight;
imageItem.ClientWidth = dispWidth;
}
else if (imageItem.ClientHeight > dispHeight)
{
Size dispSize = new Size(imageItem.ClientWidth, dispHeight);
imageDisplayer.Size = dispSize;
this.Size = dispSize;
imageItem.ClientHeight = dispHeight;
}
else if (imageItem.ClientWidth > dispWidth)
{
Size dispSize = new Size(dispWidth, imageItem.ClientHeight);
imageDisplayer.Size = dispSize;
this.Size = dispSize;
imageItem.ClientWidth = dispWidth;
}
else
{
Size dispSize = new Size(imageItem.ClientWidth, imageItem.ClientHeight);
imageDisplayer.Size = dispSize;
this.Size = dispSize;
}
}
protected override void OnMouseMove(MouseEventArgs e)
{
OnMouseMove(this, e);
base.OnMouseMove(e);
}
private void OnMouseMove(object sender, MouseEventArgs e)
{
Point current = new Point(e.X, e.Y);
current.Offset(negOffset);
Point point = GscToGoc(current);
bool result = items.LinkTest(point);
if (!result || !citem.Equals(selecteditem))
{
if (toolTipShown)
remove();
this.Cursor = Cursors.Default;
}
if (result)
{
citem = items.GetLinkItemAt(point);
if (citem != null)
{
selecteditem = citem;
Point tpoint = new Point();
if (parentIsCanvas)
tpoint = (parent as Canvas).CalcToolTipPoint(e);
if ((parent as Canvas).LinkItem != null && citem.Equals((parent as Canvas).LinkItem))
{
toolTip.Location = tpoint;
return;
}
ProcessLink(tpoint);
if (parentIsCanvas)
(parent as Canvas).ShowLinks();
}
}
if (toolTipShown)
{
toolTip.Show();
}
}
private void remove()
{
if (parentIsCanvas)
{
(parent as Canvas).removeToolTip();
(parent as Canvas).RemoveRevealedImage();
}
toolTipShown = false;
}
public void ProcessLink(Point tpoint)
{
if (parentIsCanvas)
{
(parent as Canvas).LinkItem.DrawLinkArea = true;
toolTip.Title = (parent as Canvas).LinkItem.ToolTipTitle;
toolTip.ToolTip = (parent as Canvas).LinkItem.Description;
}
toolTip.Location = tpoint;
toolTipShown = true;
toolTip.BringToFront();
this.Cursor = Cursors.Hand;
}
private Point GscToGoc(Point current)
{
if (parentIsCanvas)
return (parent as Canvas).GscToGoc(current);
return new Point();
}
private void OnClosing(object sender, FormClosingEventArgs e)
{
imageItem.ClientHeight = originalClientHeight;
imageItem.ClientWidth = originalClientWidth;
}
private void ImageRevealViewer_MouseEnter(object sender, EventArgs e)
{
Console.WriteLine("ImageRevealViewer_MouseEnter");
}
private void ImageRevealViewer_MouseCaptureChanged(object sender, EventArgs e)
{
Console.WriteLine("ImageRevealViewer_MouseCaptureChanged");
}
private void ImageRevealViewer_MouseClick(object sender, MouseEventArgs e)
{
Console.WriteLine("ImageRevealViewer_MouseClick");
}
private void ImageRevealViewer_MouseDown(object sender, MouseEventArgs e)
{
Console.WriteLine("ImageRevealViewer_MouseDown");
}
private void ImageRevealViewer_MouseHover(object sender, EventArgs e)
{
Console.WriteLine("ImageRevealViewer_MouseHover");
}
private void ImageRevealViewer_MouseLeave(object sender, EventArgs e)
{
Console.WriteLine("ImageRevealViewer_MouseLeave");
}
private void ImageRevealViewer_MouseUp(object sender, MouseEventArgs e)
{
Console.WriteLine("ImageRevealViewer_MouseUp");
}
private void ImageRevealViewer_Leave(object sender, EventArgs e)
{
Console.WriteLine("ImageRevealViewer_Leave");
}
}
}
|
|
|
|
|
Too much code!!
So badly formatted that it is impossible to read.
Cut it down to ESSENTIAL code only and enclose it in <pre></pre> tags to preserve code colouring and formatting.
Somebody might then be able to help you.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hi,
Im making an c# asp.net application. I would like to open an bin file and read the character by character. the intention is to get the most attentive characters.
Like if the content is çüëýýýëþõõ , the result must be ý. Because there are 3 characters like it.
Here are 2 pictures to see the content of the bin file:
Hex editor
Notepad
Is it possible with StreamReader ?
|
|
|
|
|
Yeah use StreamReader.BaseStream.ReadByte() that will give you a byte which you can convert to a char or hex value or int or whatever you want
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
NO
if you want to treat the file content as binary data, then you should not use anything related to characters, strings or StreamReaders, so File.OpenText() is of limits, use File.OpenRead() instead; that returns a FileStream which has Read and ReadByte methods.
Your Notepad link clearly proves the data isn't text I would say.
BTW: your question is not related to hex at all, the data is non-textual or binary, which you could show in hex format (as the left half of your hex editor does) but that is just a way of looking at it, it is not what is in there.
|
|
|
|
|
Can I find somewhere an example? I have searched on the internet but didnt find a simple example code.
|
|
|
|
|
|
Good day!
I am finally rewriting an 10 year old device-communication application in .Net. The original program uses a series of VB6 DLL's (also developed by me) to connect with all the different devices.
There are about 20 or so DLL's most of them rather unique and it would be an extremely cumbersome task to re-write all of them in .Net.
I want to create an Interface and make the DLL's conform to that.
When I try adding my DLL's in .Net it wants assembly data, which I don't have.
What is the easiest way of exposing a such a DLL's methods?
And how would I go about using an Interface to define the classes from the DLL's? (I will modify the DLL's to expose the correct methods).
|
|
|
|
|
|
You must have missed the part where I said LATEBINDING.
But thanks anyway.
|
|
|
|
|
If you want to perform late binding, you need to follow the following steps. You need to use Type.GetTypeFromProgID to retrieve the type from program ID that you want to work with, e.g. Word.Application. Create the object using Activator.CreateInstance and then use calls like InvokeMember to invoke methods in the DLL.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Pete O'Hanlon wrote: If you want to perform late binding, you need to follow the following steps. You need to use Type.GetTypeFromProgID to retrieve the type from program ID that you want to work with, e.g. Word.Application.
Hi Pete
My apologies for only replying now.
I think my problem is that there exists no such Program ID on the system, according to what I've read in Microsoft's documentation, there is a registry entry for every valid program ID. My application however, retrieves the DLL file from a DB (in a BLOB field), saves it on the HDD and then attempts to work with it.
That last bit is where I'm stuck. Do I need to register the DLL with the system in order for it to be a valid ProgramID? And furthermore, I see that the programID always conforms to {Application}.{Class} or so it seems, I'm not even sure what my DLL's programID will be even if I do manage to use it in this manner.
I'd appreciate any help you may be able to provide.
Kind Regards!
|
|
|
|
|