|
Hi,
I am new in c# [coming from the java world] and am hitting a problem.
how to you pass callbacks to the com world. I have seen plenty of example using dll (for example using windows api from c#, etc) but not using com
I use an active x control into my UI.
everything goes well, included in project, displaying ok, etc...
now, this ocx graphic component allows me to register some callback so that my gui can be aware of some components events
for example, it implements:
public abstract new void addBrowserListener ( System.Object pListener )
and defines the interface
X3DBrowserListener
if I do
ocxComponent.addBrowserListener(new X3DBrowserListener()); compiles and runs ok but not really useful
the X3DBrowserListener interface defines:
public abstract new void browserChanged ( ANIMALib.X3DBrowserEvent @event )
Sadly I got a run time:
System.InvalidCastException: No such interface supported
at xxx.X3DBrowser.addBrowserListener(Object pListener)
at xxx..ctor() in b.addBrowserListener((X3DBrowserListener)bl);
if calling
ocxComponent.addBrowserListener(new MyX3DBrowserListener());
if I define my own class as
<br />
using System;<br />
<br />
namespace xxxxxxx<br />
{<br />
[CLSCompliantAttribute(false)]<br />
public class MyX3DBrowserListener:X3DBrowserListener<br />
{<br />
public void browserChanged(ANIMALib.X3DBrowserEvent ev){<br />
System.Console.Out.WriteLine("I am here");<br />
}<br />
}<br />
<br />
}<br />
}
help very welcome!!! or any pointer to com/c# callbacks codes or samples
Cheers
Olivier down under
|
|
|
|
|
Nazila Naderi wrote:
please help me
Hmm, my first suggestion is for you to read around. You might consider reading Clipboard handling with .NET[^]. I am not entirely clear where the file name is coming from (i.e., where you are dragging it from) so the clipboard might not be the direction you want to go. More detail is really needed to identify a solution here however I would highly suggest you start reading around.
-Nick Parker
|
|
|
|
|
This should do what you need:
private void Form1_Load(object sender, System.EventArgs e)
{
this.pictureBox1.AllowDrop = true;
}
private void pictureBox1_DragEnter(object sender, System.Windows.Forms.DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
e.Effect = DragDropEffects.All;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void pictureBox1_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
{
string[] itemsInDrop = (string[])e.Data.GetData("FileDrop", false);
foreach (string path in itemsInDrop)
{
FileInfo CheckForImage = new FileInfo(path);
if(!CheckForImage.Exists)
{return;}
try
{
Bitmap newImage = new Bitmap(path);
this.pictureBox1.Image = newImage;
}
catch(System.ArgumentException)
{
MessageBox.Show("The file at " + path + " is not a valid image.", "Invalid Image", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
|
|
|
|
|
I have a statusbar which I have to draw custom panels onto inorder to changed the text color of the panel when an event happens. I add these panels in when a user does a certain action. I'm having a problem though. Everytime a new custom panel is added, it obviously re-draws the statusbar, but it changes all the panels to the same name. To try and correct this I added a foreach in, but all that did was change all the panels to the same name and write each name in the panels callection on top of each other. Any ideas on how I can solve this problem? -Thanks-
private void statusBar1_DrawItem(object sender, StatusBarDrawItemEventArgs sbdevent)
{
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Center;
Graphics g = sbdevent.Graphics;
StatusBar sb = (StatusBar)sender;
RectangleF rectf = new RectangleF(sbdevent.Bounds.X, sbdevent.Bounds.Y, sbdevent.Bounds.Width, sbdevent.Bounds.Height);
g.DrawRectangle(p, sbdevent.Bounds);
foreach( StatusBarPanel panel in this.statusBar1.Panels )
{
g.DrawString( panel.Text, sb.Font, regularColor, rectf, sf );
}
}
|
|
|
|
|
Hi,
I want to get the contents (client area) of a window as a bitmap. The window size is greater than the size of the screen i.e. it has scroll bars. All I have manage to get is the visible contents of the window.
How do I get the contents that are visible after scrolling?
I would appreciate any help.
Thanks,
Suhas
suhass
|
|
|
|
|
Suhas,
you may use Graphics.VisibleClipBounds, it return the rectangleF represents the visible contents on the window.
hope this help
azusa
|
|
|
|
|
i'm working on a server/client app and i'm running into problems.
i would like the client to update when the server sends data to it.
the problem is with Stream.Read() . This method will hang the application until either data is received, or an exception is generated.
is there a way to check if data exists before you call the read method?
this is a snippet of the code i'm using:
TcpClient tcpclnt = new TcpClient();
tcpclnt.Connect("10.10.10.10',8001);
Stream stm = tcpclnt.GetStream();
....
listen()
{
try
{
byte[] bb = new byte[100];
int k = stm.Read(bb,0,100);
for ( int i=0 ; i<k ; i++ )
txtBox.Text += (Convert.ToChar(bb[i]));
}
catch(Exception p)
{
MessageBox.Show(p.ToString());
}
}
when i call the listen method, the entire app just freezes while it waites for data.
|
|
|
|
|
|
|
leppie wrote:
threads
You said this twice, are you silently suggesting *multi-threading*?
-Nick Parker
|
|
|
|
|
Run the "listener" in its own thread. This will overcome the freeze while waiting for the server to accept your connection.
You may like to have a look at the NetworkStream.DataAvailable property, this property returns true if data is available on the stream to be read; otherwise, false.
|
|
|
|
|
Hello!
We are currently struggling with a problem of extending Microsoft PowerPoint (PP) freehand line functionality.
Here is our objective:
Imagine you have a brush in your hand and you are drawing a line. You can easily change the thickness of this
line while drawing by controlling the pressure on the paper. So after you drew it the line has many different
thicknesses in it depending on how many times you changed the pressure while drawing. Back to PP…
We need something like a freehand line, but the output will not just be a line that has the same thickness on
the whole length of it. The thickness varies depending on some logic (black box) that is implemented by our
algorithm. Image you inherit from “freehand line” object and extend it by characteristics described in the brush
example (different thicknesses contained by one continuous line). We need something that behaves the same way
when you scale it (zoom) like lines in PP do. That means that the thickness of line is not affected by scaling,
opposite to objects in PP, which change their shapes while scaling.
We have written our own OLE server, which creates such line, but when we copy it into PP it becomes an object
that does not scale like a line - it changes its shape while scaling.
We think that one of possible directions could be to find out the structure and format of all possible object
types supported by MS Office (Lines, Shapes, objects, etc). Examine them and find the one that has the closest
match to our requirements. Then inherit from it, extend it and introduce it SOMEHOW to PP as a new custom drawing
object type/class. We have not found any information on types and formats or the possibility to extend the standard
graphical office objects types by custom graphical objects. Maybe if you spent a lot of $$ on MS Certificates and
you have a certain level of support this information and appropriate framework is accessible to you?
We think that this problem requires a real expert in MS Office Area therefore we post it here.
Any help will be gratefully appreciated.
Cheers,
gicio
|
|
|
|
|
Okay im trying to learn server side programming and i just want to know is it possible to create a program that list all the computers on a network then puts them all in a listbox then you can select a computer and that computer we'll be shown a message box or something like that
Basically im tryin to build a program like freeze tag for computers.
I know c# pretty well but i don't know how to list the computers on the network then how would i show them a message box or something like that.
Uh i know it kinda detailed but any help would be greatly appreciated.
Thanks alot
Da Intern
|
|
|
|
|
There is some helpful code in my MyDUMeter article, look at the ... o here you go:
[DllImport("Netapi32")]
private static extern int NetServerEnum(
string servername,
int level,
out IntPtr buffer,
int maxlen,
out int entriesread,
out int totalentries,
int servertype,
string domain,
int resumehandle);
[DllImport("Netapi32")]
private static extern int NetApiBufferFree(IntPtr ptr);
[StructLayout(LayoutKind.Sequential)]
internal class ServerInfo
{
public int platformid;
[MarshalAs(UnmanagedType.LPWStr)]
public string name;
public int majorver;
public int minorver;
public int type;
[MarshalAs(UnmanagedType.LPWStr)]
public string comment;
}
class MachineConvertor : TypeConverter
{
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
{
int eread, etot;
IntPtr buffer;
int l = 200;
int size = Marshal.SizeOf(typeof(ServerInfo));
int res = NetServerEnum(
null,
101,
out buffer,
size * l,
out eread,
out etot,
3,
null,
0);
IntPtr p = buffer;
ArrayList arr = new ArrayList(etot);
for (int i = 0; i < eread; i++)
{
ServerInfo si = Marshal.PtrToStructure(p, typeof(ServerInfo)) as ServerInfo;
if (si.majorver > 4 && si.name != "")
arr.Add(si.name);
p = (IntPtr)((int)p + size);
}
res = NetApiBufferFree(buffer);
return new StandardValuesCollection(arr);
}
public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
{
return true;
}
}
leppie::AllocCPArticle("Zee blog"); Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.
|
|
|
|
|
what is the difference between [,] & [][]? It looks same. But I can't cast one to another.
Thanks in advance!
|
|
|
|
|
This[^] should explain everything...
Hawaian shirts and shorts work too in Summer.
People assume you're either a complete nut (in which case not a worthy target) or so damn good you don't need to worry about camouflage...
-Anna-Jayne Metcalfe on Paintballing
|
|
|
|
|
The names are descriptive as well. Multi-dimension array is obvious. And a jagged array can contain different length arrays - a jagged edge if you did a graphical representation.
|
|
|
|
|
How to do the realloc() in C# like in C?
|
|
|
|
|
What do you mean? How did you call malloc() in C#?
You can do it on anything you choose - from .bat to .net - A customer
|
|
|
|
|
Use ArrayList s rather than arrays. They will grow automatically.
|
|
|
|
|
I realize I can get a list of controls on the form by writing
this.Contols;
Is there a simple way to get the controls collection back sorted by tab order?
thanks
|
|
|
|
|
I don't think there is a way built into the framework to do this - would probably require the use of some kind of sortable collection EG SortedList or ArrayList...
|
|
|
|
|
That seems to be a good start. List the Controls in the SortedList and write a custom comparer:
//somewhere in the code
SortedList myList = new SortedList(yourComparer, this.Controls.Count);
foreach(Control ctl in this.Controls){
myList.Add(ctl);
}
//somewhere else
class ControlComparer : IComparer {
public bool Compare(object obj1, object obj2){
Control ctl1 = (Control)obj1;
Control ctl2 = (Control)obj2;
bool returnValue = false;
//compare and set [returnValue]
return returnValue;
}
}
|
|
|
|
|
I was thinking of something more like:
SortedList ControlListByTabIndex = new SortedList();
foreach(Control CurrentControl in this.Controls)
{
ControlListByTabIndex.Add(CurrentControl.TabIndex, CurrentControl);
}
for (int i = 0 ; i < ControlListByTabIndex.Count ; i++)
{
Console.WriteLine(((Control)ControlListByTabIndex.GetByIndex(i)).TabIndex);
Console.WriteLine(((Control)ControlListByTabIndex.GetByIndex(i)).Name);
}
|
|
|
|
|
Thank you.
It turns out that controls have a GetNextControl() property. This avoids the need to recursively iter throught tab controls and frame controls.
thanks again.
|
|
|
|