|
It's not working because your code is asking for all custom attributes on the Button class, not on your button1 field.
Here's how you should get custom attributes from a field:
Type myFormType = typeof(MyForm);
FieldInfo button1Field = myFormType.GetField("button1", BindingFlags.NonPublic | BindingFlags.Instance);
object[] customAttributes = button1Field.GetCustomAttributes(typeof(myattribute), false);
|
|
|
|
|
|
Rather than looking at the class, you have to look at the fields that belong to the class. Try this instead:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
namespace Test
{
[AttributeUsage(AttributeTargets.All)]
public class myattribute : Attribute
{
public myattribute() : base() { }
}
public partial class Form1 : Form
{
[myattribute]
Button b1;
public Form1()
{
b1 = new Button();
this.Controls.Add(b1);
FieldInfo[] fis = this.GetType().GetFields(
BindingFlags.Instance | BindingFlags.NonPublic |
BindingFlags.Public);
foreach (FieldInfo fi in fis)
{
object[] o = fi.GetCustomAttributes(typeof(myattribute), true);
if (o.Length != 0)
{
Console.WriteLine("Hello from o");
}
}
}
}
}
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
|
Can anyone help?
I want to be able to drag and drop text into a Rich Text Edit or Memo type component but I want to drop the text at the position of the mouse cursor when the mouse button is released?
I have read a few articles so I can do drag and drop but how to drop at the mouse cursor position?
Thanks In Advance
|
|
|
|
|
I would suggest utilising the MouseUp event handler, and use HitTestInfo to find the coordinates of the pointer...
HitTest(e.X,e.Y)
Then set the cursor to this position, then perform your drop method at that position
Hope this helps
Give me strength, give me caffeine
|
|
|
|
|
Hey people
Was just wondering whether anyone knew whether this if statement is gonna be system dependent or not
e.KeyChar == 13, where e is a KeyPressEventArgs
Am trying to allow a text box to perform an action when return is pressed
The method works on my comptuer, but will it on another keyboard?
Cheers
Give me strength, give me caffeine
|
|
|
|
|
It's not system dependent because if you look at ASCII Table you can see that it's a standard notation for CR.
c#_keithy wrote: e.KeyChar == 13
My recommendation is to use the Keys enumeration to compare with e.KeyChar
Hope it helps.
There are 10 kinds of people: those who understand binary and those who don't
|
|
|
|
|
Just found an mdn article on using Keypress events, which uses the following compare statement
e.KeyChar == (char)Keys.Return
KeyPressArticle[^]
Thanks for your input
Give me strength, give me caffeine
|
|
|
|
|
Hi,
I am able to list all available providers in the system presently windows using c#.
I can do that with the wql query i.e. select * from __Provider. But if i want to determine what type of provider it is, like say an instance provider or method provider etc then how do I determine that?
Also different classes use different types of providers like classes with events use event providers and those with use of methods use method provider.
But how to determine which event or method provider etc is being used by the class?
|
|
|
|
|
First og all.....I'm a newbee.....!!!
I need to make a service, that on a given time executes an application (APPL_1).
Furthermore I need to be able to tell the service to execute APPL_1 manually from another og my C# applications (APPL_2) by clicking a button.
So what I need is a way to "communicate" between the service and APPL_2 in order to execute APPL_1.
I hope the above isn't to cryptic.. *ss*
All kind of "help" would be appriciated.
/Lars Lie
|
|
|
|
|
If you need to communicate between processes, you have several options.
Look up a technology called .NET remoting. It allows you to "communicate" with other processes. There are several articles and examples on this site.
There are plenty of other options too: web services (your service exists on the web, called by either other web applications or desktop applications), as well as the new Windows Communication Foundation technology (WCF). Any of those 3 should work for you.
|
|
|
|
|
Since there's no default method that let's me unhook all listeners from an event at once, I sometimes do this:
public event PropertyChangedEventHandler PropertyChanged;
public void UnHook()
{
if (this.PropertyChanged != null)
{
Delegate[] list = this.PropertyChanged.GetInvocationList();
foreach (Delegate d in list) this.PropertyChanged -= d as PropertyChangedEventHandler;
}
}
However, since I find it kind of annoying to write this code for different types of events I'd really like to be able to do something this:
public static void Unhook<T>(event x)
{
Delegate[] list = x.GetInvocationList();
foreach (Delegate d in list) x -= d as T;
}
My question: Does anyone know of a way to implement parsing of events as method arguments? Thanks in advance...
Standards are great! Everybody should have one!
|
|
|
|
|
Let me point you over towards EventPools[^]. They tackle the management of events in a different way.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Ok, that looks promising, thanks. Still I'm curious if it's in anyway possible to realize parsing of events as arguments...
Standards are great! Everybody should have one!
|
|
|
|
|
Great article. I'm going to explorer this idea some more for some UI stuff I'm currently working on.
|
|
|
|
|
Thanks for that. Ever since I first stumbled on Marc's article I've found it easier to use EventPools. This article just grew out of my heavy use of EventPool - BTW, it makes implementing the MVC pattern really straight forward.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Hello Developers. I realize this is a C# message board but I can't help but ask folks for advice. I recently upgraded our teams Sharepoint site from 2.0 to 3.0. I've run into a problem adding a content database but I'm afraid my biggest problem is I can't change the configuration database. As of right now, the site and the databases are on separate servers but we need them on the same server. If anyone can help me with this problem or send me a link that could help, I'd greatly appreciate it. Thanks for all responses in advance.
Lester
http://www.lestersconyers.com
|
|
|
|
|
hi friends
i want to read a txt file using c#. i have some txt files with different informations. ex
txt 1
customr:abc
article:zxy
page number: 4
txt 2
customr:fgh
article:ser
page number: 3
txt 3
customr:yhu
article:fgr
page number:10
the problem is : how i can find the value. how to read this txt file. i tried. but it is reading only if we fave given the full length. i want to find what will be the value of customer of txt 1.
plz do help me.
thank u.
|
|
|
|
|
string text = File.ReadAllText(filename)
You can then search for different strings within your string using IndexOf, Substring etc. If you don't like this approach study MDSN for System.IO.File class. It has a lot of static methods that can help you read a text file in different ways.
Do your best to be the best
|
|
|
|
|
You can use the readline function of the StreamReader. If the line contains the desired text such as txt 1, then read the next line and you will get the customer name etc.
|
|
|
|
|
Hi all,
How can i convert a PDF to JPG image page by page. Also I wish to save the images with the page number as file name.
For Eg:
If the PDF has 5 Pages. The first page should be converted as jpg and saved in the name as 1.jpg, for the second page 2.jpg................5.jpg
Is it possible to create this without using any third party tools/DLL. I wish to cretae this application using C#.NET 2.0
Plz help me.
Thanks in advance
Know is Drop, Unknown is Ocean
|
|
|
|
|
Exelioindia wrote: Is it possible to create this without using any third party tools/DLL.
The reason third party libraries exist is that C# has no support for this. Otherwise, no-one would buy the libraries. The PDF standard is free to download, your other option is to write your own, or look around source forge for something free.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi,
Thanks for your suggestion. Now i got clear. Is there any dll with source, so that i can learn how they did it. Plz give me some samples to link's from where i can learn myself and do it.
Thanks once again
Know is Drop, Unknown is Ocean
|
|
|
|
|
Christian already pointed you towards SourceForge. Try there.
Deja View - the feeling that you've seen this post before.
|
|
|
|