|
Thanks Dave.
Yes you're right it does work, but I am dumb and FileInfo was looking in the wrong directory. I even double checked the path but I skipped a folder... how do people make these kinds of mistakes happens I guess, thanks for your reply.
|
|
|
|
|
Hi All,
I've been looking around for any pointers on how this might be 'dressed up' in some form of 'catch all' generic call to based on a string key value.
I guess this would involve reflection in order to get at the class properties. Has anyone come across something like this?
I would like to be able to use syntax like along the lines of:
public T GetSettingValue<T>(string key)
{
return (T)Properties.Settings.Default.Properties[key].Value;
}
Cheers,
|
|
|
|
|
|
You can draw directly on the form. This example just draws a diaganol line from top left to bottom right. Abviously you'll need to persist your points in a collection somewhere and alter the OnPaint accordingly, but it should get you started.
using System.Drawing;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs e)
{
using (Pen pen = new Pen(Color.Black))
{
e.Graphics.DrawLine(pen, Point.Empty, new Point(ClientSize.Width, ClientSize.Height));
}
base.OnPaint(e);
}
}
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Thanks for the help, i have used a similar code and it gives me one specific point(in form of a small ellipse is fine with me). how can i get similar points on mouse clicks.
protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
e.Graphics.DrawEllipse(Pens.Red, 100,100, 2, 2);
base.OnPaint(e);
}
please help
|
|
|
|
|
Grab the location of click in the Form's MouseDown event. Then, you can use them as center of your circle(point) and calculate the X and Y coordinates for the DrawEllipse method.
|
|
|
|
|
Something like:
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
List<Point> points = new List<Point>();
public Form1()
{
InitializeComponent();
MouseClick += new MouseEventHandler(Form1_MouseClick);
}
void Form1_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
points.Add(e.Location);
Invalidate();
}
}
protected override void OnPaint(PaintEventArgs e)
{
foreach (Point point in points)
{
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
e.Graphics.DrawEllipse(Pens.Red, point.X, point.Y, 2, 2);
}
base.OnPaint(e);
}
}
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Hi, All.
I need some solution to get the list of Types marked with user defined attribute.
I got few DLLs with definitions of protocol messages, which marked with some attribute ("MessageAttribute").
My mission is: to collect all Types marked with this attribute.
The DLLs - created by few different teams and have dependencies between dlls.
When I trying to load some dll by calling:
asm = Assembly.LoadFile(dllFileName)
and than to get Types list by:
asm.getTypes() - But here I get System.Reflection.ReflectionTypeLoadException.
As I see the exception caused by some Type from outer DLL.
All DLLs in same directory. I tryed also to add:
AppDomain.CurrentDomain.TypeResolve += new ResolveEventHandler(MyAssemblyResolve);
But id doesn't get into resolving function.
|
|
|
|
|
Did anyone know how to use NI-DAQmx USB600 to send out a voltage to change the input of device? any idea or suggestion? I have a GUI now, i wanna the GUI switch between Active high(5V) and Active low(0V).
|
|
|
|
|
This is the C# forum.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
YEP, i wanna use C# to program it.
|
|
|
|
|
Hi All,
I have a DLL file I am using in a .Net 3.5 Windows Forms Application, it is a 32-bit DLL.
Now when I run on 64-bit windows it does not work - Understandable.
I also have a 64-bit version of this file, but my question is how do I switch between the two? Obvisouly I could make two version of the application one for 32Bit that uses the 32Bit DLL and one for 64bit that uses the 64Bit dll, but is this needed? Can I not simply include the two version of the DLL in my application and somehow check which platform is running and use the relevant DLL to suite?
Any Ideas?
Thank you
P.S. My searching skills on this are not working (possible as I can not think of the correct phrase to search)
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
musefan wrote: Obvisouly I could make two version of the application one for 32Bit that uses the 32Bit DLL and one for 64bit that uses the 64Bit dll, but is this needed?
Yes.
You can run a 32-bit app within a 64-bit OS, not the other way of course, and I believe you should be able to call a 32-bit dll from a 64 bit app. That said, it is a better idea to provide two versions - 32bit and 64bit - of the application.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
I completely agree with the logic of two application version but was just hoping as the majority of my application with work with windows 64bit that I could just decide the DLL to use at runtime. It is definitely an issue using the 32bit DLL on 64bit windows.
Thanks for you input
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
This[^]is not what you need, but might help you device a way to accomplish your task.
Another thought that came to my mind is adding references through code. You can check if the system is 32 or 64 bit and add reference accordingly. However, I am not sure how big a change you code will undergo if you follow this approach.
Best way, IMO and as stated by Vilmos, would be to have to versions - one for 32-bit and other for 64.
modified on Thursday, July 16, 2009 11:54 AM
|
|
|
|
|
d@nish wrote: and as stated by Nagy
psst: It's Vilmos, but don't tell anyone!
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
Oh...modified.
|
|
|
|
|
I said don't tell everyone, sheesssh!
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
Hi,
i have a Class User which inherits from other classes:
public class User : BizObject, INotifyPropertyChanged
{
In another class I want to get all members of the User Object using Reflection:
class ObjectHelper<T>
{
public static Dictionary<string, List<Object>> Compare(T oldObject, T newObject)
{
Type type = typeof(T);
Dictionary<string, List<Object>> props = new Dictionary<string, List<Object>>();
PropertyInfo[] properties = type.GetProperties(BindingFlags.DeclaredOnly);
As far as I understand the BindingFlags.DeclaredOnly flag, inherited members should not be considered.
But in my case this flag delivers absolutely no properties.
When I just use type.GetProperties() without flags, I get all members, including the (not wanted) inherited ones from the BizObject Class.
|
|
|
|
|
That's because the overload with no arguments calls the overload with a flag argument with the flags (Public | Static | Instance)
If you add those flags to your DeclaredOnly, you should get what you want.
Reflector to the rescue!!
|
|
|
|
|
Thank you, it works now
|
|
|
|
|
Hi,
I'm toying around with generics and have run into a little problem. My class is a tree, but this is not about whether or not one should make a tree this way - what I'm trying to do adds complexity for just a little lazy-coding benefit, so please ignore the particular example - I just want to understand if what I wanted to do can be done with generics.
Here's the TreeNode class:
abstract public class TreeNode<T>
{
TreeNode<T> parent;
List<TreeNode<T>> children = new List<TreeNode<T>>();
T data;
public TreeNode() { }
public T Data
{
get { return data; }
set { data = value; }
}
public TreeNode<T> Parent
{
get { return parent; }
set { parent = value; }
}
public List<TreeNode<T>> Children
{
get { return children; }
set { children = value; }
}
}
Now, let's say we want to derive a class for organizing tags into trees. The data is just a string, and for convenience we may want a constructor that sets the text of the node. I'm trying to see if there is a way to write a utility method that would take any treenode (necessarily derived since the base class is abstract) and a collection of node *data* objects and create child nodes with the data and parent set. The following snippet illustrates the Tag and how code might use the utility method to create a hard-coded hierarchy of tags:
public class Tag : TreeNode<string>
{
public Tag() {}
public Tag(string text) { Data = text; }
}
class usingTags
{
Tag getBuiltIn()
{
Tag root = new Tag("Built-in");
Tag[] top = TreeUtil.Add<Tag>(root, "License", "Product");
TreeUtil.Add<Tag>(top[0], "CPOL", "MIT", "Proprietary");
TreeUtil.Add<Tag>(top[1], "Banco", "Acco", "Piccolo");
return root;
}
}
Based on this, the utility method should be something like this:
static public TNode[] Add<TNode, T>(TNode parent, params T[] data) where TNode : TreeNode<T>, new()
{
List<TNode> list;
if (parent == null)
list = parent.Children;
else
list = new List<TNode>();
int startIndex = list.Count;
foreach (T item in data) list.Add(new TNode() { Data = item });
return list.GetRange(startIndex, list.Count - startIndex).ToArray();
}
Two problems present themselves:
1) The first assignment to "list" does not build, the compiler complaining it cannot convert List<TreeNode<T>> to List<TNode>, which I think is odd since I have defined a type constraint which guarantees that TNode either is or is derived from TreeNode<T>.
2) If I change that assignment so it assigns null instead, just to be able to build, the code *using* it does not compile. I thought the type of T could be inferred, since TNode is TreeNode<T> and the params T[] parameter is an array of strings. But the compiler just says the method requries two type parameters.
Is there a way to solve these problems so the user of the utility method need only supply the node type to create and the actual values for node data?
|
|
|
|
|
You might want to edit that, pasting your code again with "Encode HTML tags when pasting" set. Gets me every time, too (and normaly the other way - set when I want it off - as well).
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
The problem is that it then does that to the <pre> tags as well... But I guess that is at least preferrable to losing all the generics "tags". Thanks for pointing it out.
|
|
|
|
|
It's "Do not interpret HTML tags" that screws up pre tags in a post. Encode HTML tags when pasting only affects stuff in your paste buffer, and normally you don't copy/paste pre tags.
The European Way of War: Blow your own continent up.
The American Way of War: Go over and help them.
|
|
|
|
|