How do I call Zedgraph's function masterPane.SetLayout() from Web C# Application?
Basically i'm stuck at step myMasterPane.SetLayout(g, PaneLayout.SingleColumn);
How do I create that variable g which is supposed to be a Graphic()
I tried Graphics g = new Graphics(); and Graphics g;
none of these work.
new Graphics() gives me Error 2 The type 'System.Drawing.Graphics' has no constructors defined
and anyways I'm assuming this needs to be initialized somehow.
One important difference that I want to do vs the example below is that I want to go directly from my master pane to an image using
masterPane.GetImage(), my issue is I can't get that masterpane setup unless I find a way to call myMasterPane.SetLayout()
I found this article but I can't get this working
http://zedgraph.org/wiki/index.php?title=Use_a_MasterPane_in_a_web_page
The page you linked to shows exactly how to do this. Did you try their example?
The example gets the Graphics instance passed to it in the RenderGraph event handler.
Related
I am new to C# and i am making a Tic-Tac-Toe game in Visual Studio 2010. I've already made the whole structural part of it, but i am having trouble loading images from pictureBoxes. The command i am using is pictureBox.Load(string imageUrl), and it works fine when i use it on the method TicForm_Load, since TicForm is a Form:
private void TicForm_Load(object sender, EventArgs e)
{
//picture1 is the name of a pictureBox created on TicForm.cs (Design)
picture1.Load(imageUrl);
}
However, in my game, the changes to the images in the pictureBoxes are controlled by a class called Board. I want to be able to change images from this class.
I've already set the modifiers of the pictureBoxes to public, yet, if i want to access a command from TicForm, the program asks me to instantiate an object of the type TicForm first:
//Somewhere on the class Board
TicForm ticform = new Ticform();
ticform.picLocation00.Load(imageUrl);
This, however, causes an exception StackOverflow, since i create a new Board, at the start of the TicForm class, and i create a new TicForm, at the start of the Board class.
I would really appreciate an answer from someone with more experience / knowledge in Visual Studio than me. How do you normally change the images from the pictureBox in run-time? Am i doing something wrong?
It's been solved. Instead of using a method from TicForm into a class (which would never work), i created new variables on the class that indicate in what circustamces the method is to be used, and this happens inside the TicForm class.
In a program I wrote, I came up with functionality for a User Control, so I decided to break it out into its own project/DLL. The control consists of two buttons and a panel. When I use the DLL, however, I am missing a critical piece of functionality - I can no longer change the AutoScrollPosition of the panel! My hunch is that I'm getting a copy, not a reference to the property when I go to set it... So here's an idea of the code:
// this works when the user control is native to my project
panelContainer.AutoScrollPosition = new Point(0, myVal + 1);
// this doesn't work when the user control is Referenced in my project
FromDLL.panelContainer.AutoScrollPosition = new Point(0, myVal + 1);
I can change other properties on the FromDll.panelContainer, such as the name, but I can't change AutoScrollPosition. Other properties between the two are exactly the same (AutoScroll = false, etc...). To top it off, when I create Setter method in the DLL, the calls work:
// Call from project to set DLL's reference to native panel
FromDLL.SetMainPanel(nativePanel);
// Now this works after the call to SetMainPanel
FromDLL.panelContainer.AutoScrollPosition = new Point(0, myVal + 1);
Any ideas on why I'd be getting a copy of the AutoScrollPosition instead of a reference?
You need to check up your control client size, versus System.Windows.Forms.ScrollableControl.AutoScrollMinSize. Also, make sure your System.Windows.Forms.ScrollableControl.AutoScroll is true and take into account System.Windows.Forms.ScrollableControl.AutoScrollMargin with System.Windows.Forms.ScrollableControl.AutoScrollOffset. It's possible that you simply did not understand the concept, as happens with some members in the past.
This is the article with minimalistic and clear explanation of matter:
https://web.archive.org/web/20141229163946/http://bobpowell.net/understanding_autoscroll.aspx.
See also:
http://msdn.microsoft.com/en-us/library/system.windows.forms.scrollablecontrol.aspx.
I used reflection a couple of time to get values from the screen element, call methods etc. But now I am working on an application called Avaya, as this is not a really famous application I cannot find any help. My goal is to get some fields from this application, using automation UI library is not possible as the fields are not visible with any UI inspector like Spy++ and etc..
The only way to solve my issue is to develop a small code that interrogate the application and the result will be what is available for me, each method, each value, etc..
Then I have to start from the interface, I went to regedit and I got a list of 20 interfaces, then I start my code looping at these interfaces to get all classes and after that loop to each methods and proprieties, is that correct? Then I start my code getting a type and creating and instance..:
try {
foreach (string ThisInterface in ArrayInterfaces)
{
ThisInterfacee = ThisInterface;
//Call this interface
Type AvayaWorkspaceType = Type.GetTypeFromProgID(ThisInterface, true);
//Create Instance of this
object workspace = Activator.CreateInstance(AvayaWorkspaceType);
Any ideas of how to continues??
Thanks a lot any suggestion is welcome :)
I use reflection and C#
Solution: Reason why I am not able is because Reflection will only work with .NET base application, for other applications you should use IUIautomation or user32.dll
I am trying to set individual pixels on a Gtk.Image widget. The documentation states that the ImageProp property of a Gtk.Image returns a Gdk.Image which seems to let you edit the individual pixels, but whenever I use this it only returns null.
My solution so far is to load the image from disk as a System.Drawing.Bitmap, edit it, save it to a temporary file, then load it back into a Gtk.Image, but this is obviously not ideal.
For
Gtk.Image image = new Gtk.Image("images/test.png");
Gdk.Image gdkImage = image.ImageProp;
Why is gdkImage always null?
The image itself loads and displays correctly.
Although I have no prior experience with GTK# or C#, based on whatever little I know about Gtk & what I could look up online, I will make an attempt to provide some inputs.
You can get Gdk.Image for a Gtk.Image only if you have created the Gtk.Image from a Gdk.Image using the mentioned property, otherwise you will get null as in your case where you are creating it from a file or as suggested by creating it from Gdk.Pixbuf. In current case, you could try to get Gdk.Image from Gdk.Drawable using Gdk.Drawable.GetImage method or use Gdk.Image.Get method. You can make use of GdkWindow associated with Gtk.Image as Gdk.Drawable in the mentioned cases. For Gdk.Window to be valid the widget should have been shown or realized. But it is quite likely that you may end with null in both the cases.
Side Note: GdkImage APIs are deprecated in the newer versions of Gtk, please note it may not be so in the case of GTK# as yet.
Thus it might be a good idea to use Gdk.Pixbuf instead. It is possible to get pixels for GdkPixbuf and modify the same in GTK. But unfortunately it appears that in case of GTK# that particular property (Pixels) of Gdk.Pixbuf is made as read only. One option maybe to use Gdk.Pixdata from Gdk.Pixbuf which is created from the image, modify the pixels using methods in Gdk.Pixdata, create a Gdk.Pixbuf out of it & copy that back to the original Gdk.Pixbuf. Unfortunately I cannot be sure about this, you can give it a shot though.
Alternatively you can consider drawing onto Gdk.Drawable. There are examples available wherein the Gdk.Drawable assocaited with Gtk.Widget (usually Gtk.DrawingArea) is updated in the Expose Event callback.
I hope that the information provided can provide you with some pointer to proceed.
Use Pixbuf first:
Gdk.Pixbuf pixbufImage = new Gdk.Pixbuf(#"images/test.png");
Gtk.Image gtkImage = new Gtk.Image(pixbufImage);
Gdk.Image gdkImage = gtkImage.ImageProp;
I have a windows form with a listview control. I have a selectedIndex changed event where i am performing some action. Through reflection I am trying to set the value of the list view.
But the event is not getting fired. Any help will be helpfull.
Edit
The event looks like
private void LV1_SelectedIndexChanged(object sender, EventArgs e)
{
if (LV1.SelectedItems.Count>0)
{
if (LV1.SelectedItems[0].Text.ToString() == "testing")
{
// Do some work.
}
}
}
I am using relection in another project and changing the selected item as follows
Assembly a = Assembly.LoadFrom(exePath);
Type formType = a.GetType(formName);
testForm = (Form)a.CreateInstance(formType.FullName);
if (testForm != null)
{
Type t1 = testForm.GetType();
FieldInfo fi = t1.GetField(controlName, flags);
object ctrl = fi.GetValue(testForm);
ListView l1 = (ListView)ctrl;
l1.Items[0].Selected = true;
}
Automating another application is fun howver not a trivial task. There's a few options but I guess most of them is out of scope for you. One would be to programatically take over the mouse and keyboard and trough those channels manage the program. Another way would be to manipulate memory, As I said neither are trivial to implement and very easily broken if the aplpication is updated.
I would suggest instead of trying to automate the application to look for infliction points. Are there any service endpoints you could automate and achieve the same result? any API or dll's used by the application you could use instead?
If you really have to automate the application there do exist several frameworks for doing that (usually build for testing purposes). The only one I can think off right now is made by Assima as is ment for training purposes.
I think your problem is here:
testForm = (Form)a.CreateInstance(formType.FullName);
You are creating a new instance of the form. I'm assuming your main project is an exe that runs an shows the form. Your second project is then another exe that runs and wants to change the selected item. By creating a new instance of the form you will be changing the selected item on the new form, not the old one.
What you need to do is somehow pass the form object over to the secondary project. possibly some static method that gets a singleton instance of the form maybe.
I'm still not entirely sure why you are using reflection, you could just give the second project a reference to the first.
The first question I'd ask is: why are you using reflection here? Just set the value through the public API. If you are messing underneath the public API, then yes: it is entirely possible that some events won't get fired.
Perhaps if you could show us exactly how you are doing this?