|
Wow... thanks, Patrick.
Hmm, this is not the behaviour one would expect, but who
says life should be predictable .
My workaround was:
-----------------------------
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace RegionTest
{
public partial class Form1 : Form
{
RegionData[] regionData = new RegionData[2];
int currRegionIndex = 0;
MyControl myControl = new MyControl();
public Form1()
{
InitializeComponent();
GraphicsPath gp0 = new GraphicsPath();
gp0.AddEllipse(myControl.ClientRectangle);
regionData[0] = (new Region(gp0)).GetRegionData();
GraphicsPath gp1 = new GraphicsPath();
gp1.AddRectangle(myControl.ClientRectangle);
regionData[1] = (new Region(gp1)).GetRegionData();
myControl.Region = new Region(region[0]);
Controls.Add(myControl);
}
private void button1_Click(object sender, EventArgs e)
{
currRegionIndex = (currRegionIndex + 1) % 2;
myControl.Region = new Region(regionData[currRegionIndex]);
myControl.Refresh();
}
}
}
-----------------------------
which in the end is similar to yours in efficiency (I guess)
but yours is more elegant.
Tom
|
|
|
|
|
hi all,
am getting a stange problem. from a call back function, am calling a MODELESS dialog,(when timeout reached for my dialog), but it's creating as a modal dialog... it's not my requirement. i've develop a sample,i think, it's created on a different thread than main thread. (may be.. not sure.).... please provide any commentsa nad solution.. please...
my code:(design form not included)
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Threading;
namespace TimeoutWindow
{
public partial class TimeoutForm : Form
{
private System.Threading.Timer m_Timer = null;
private const int WH_KEYBOARD = 2;
private const int WH_MOUSE = 7;
private LowLevelKeyboardProc _procKey = KeyHookCallback;
private LowLevelKeyboardProc _prockMouse = MouseHookCallBack;
private static IntPtr _hookIDKey = IntPtr.Zero;
private static IntPtr _hookIDMouse = IntPtr.Zero;
private static UInt32 m_LastHitTime = 0;
private System.Threading.TimerCallback timerCallBack = null;
private AutoResetEvent autoEvent = null;
private Form2 dlg;
private delegate IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam);
public TimeoutForm()
{
InitializeComponent();
_hookIDKey = SetWindowsHookEx(WH_KEYBOARD,_procKey,(IntPtr)0,(uint)AppDomain.GetCurrentThreadId());
_hookIDMouse = SetWindowsHookEx(WH_MOUSE,_procKey,(IntPtr)0,(uint)AppDomain.GetCurrentThreadId());
timerCallBack = new System.Threading.TimerCallback(this.CheckTimeout);
autoEvent = new AutoResetEvent(false);
m_LastHitTime = GetTickCount();
m_Timer = new System.Threading.Timer(timerCallBack, autoEvent, 20000, 20000);
}
private void OnTryLogin(object sender, EventArgs e)
{
MessageBox.Show("HI");
Form2 dlg = new Form2();
dlg.ShowDialog();
}
public void CheckTimeout(Object stateInfo)
{
autoEvent = (AutoResetEvent)stateInfo;
UInt32 curTime = GetTickCount();
if (curTime - m_LastHitTime > 2000)
{
this.m_Timer.Dispose();
try
{
this.dlg = new Form2();
if (dlg != null)
{
//problem occuring here................
this.dlg.ShowDialog(); /// creating modal dialog.
m_LastHitTime = GetTickCount();
m_Timer = new System.Threading.Timer(timerCallBack, autoEvent,2000,2000);
}
else
System.Windows.Forms.MessageBox.Show("NULL");
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
}
}
#region dllimport
[System.Runtime.InteropServices.DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr SetWindowsHookEx(int idHook, LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadId);
[System.Runtime.InteropServices.DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool UnhookWindowsHookEx(IntPtr hhk);
[System.Runtime.InteropServices.DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam);
[System.Runtime.InteropServices.DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr GetModuleHandle(string lpModuleName);
[System.Runtime.InteropServices.DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern System.UInt32 GetTickCount();
#endregion
private static IntPtr KeyHookCallback(int nCode, IntPtr wParam, IntPtr lParam)
{
if (nCode < 0)
return CallNextHookEx(_hookIDKey, nCode, wParam, lParam);
else
{
m_LastHitTime = GetTickCount();
return CallNextHookEx(_hookIDKey, nCode, wParam, lParam);
}
}
private static IntPtr MouseHookCallBack(int nCode, IntPtr wParam, IntPtr lParam)
{
if (nCode < 0)
return CallNextHookEx(_hookIDMouse, nCode, wParam, lParam);
else
{
m_LastHitTime = GetTickCount();
return CallNextHookEx(_hookIDMouse, nCode, wParam, lParam);
}
}
private void OnCloseForm1(object sender, FormClosedEventArgs e)
{
UnhookWindowsHookEx(_hookIDKey);
UnhookWindowsHookEx(_hookIDMouse);
}
}
}
-- modified at 15:56 Monday 10th September, 2007
kamalesh
|
|
|
|
|
kamalesh82 wrote: am calling a modal dialog,(when timeout reached for my dialog), but it's creating as a modal dialog
If you don't want a modal dialog, then call Show instead of ShowDialog. Or, have I missed what the problem is ?
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 )
|
|
|
|
|
sorry for the typing mistake,... i neead modal, but it's creating modeless... .
kamalesh
|
|
|
|
|
OK, perhaps you're right, you're on another thread, and that is the problem.
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, In my game that I'm making I have a 2D Array of Picture boxes. Using a function:
<br />
<br />
image_arr[0] = Bulldozer_2._0.Properties.Resources.empty;
image_arr[1] = Bulldozer_2._0.Properties.Resources.wall;<br />
image_arr[2] = Bulldozer_2._0.Properties.Resources.target;<br />
image_arr[3] = Bulldozer_2._0.Properties.Resources.rock;<br />
image_arr[4] = Bulldozer_2._0.Properties.Resources.target_w_rock;<br />
image_arr[5] = Bulldozer_2._0.Properties.Resources.bulldozer_down;<br />
image_arr[6] = Bulldozer_2._0.Properties.Resources.bulldozer_up;<br />
image_arr[7] = Bulldozer_2._0.Properties.Resources.bulldozer_left;<br />
image_arr[8] = Bulldozer_2._0.Properties.Resources.bulldozer_right;<br />
<br />
const Byte IMAGE_WIDTH = 32;<br />
const Byte IMAGE_HEIGHT = 32;<br />
<br />
PictureBox[,] PicBoxes = new PictureBox[MAX_ROWS, MAX_COLS];<br />
<br />
private void draw_image(Byte type, int row, int col)<br />
{<br />
PicBoxes[row, col] = new PictureBox();<br />
PicBoxes[row, col].Name = "pictureBox1";<br />
PicBoxes[row, col].Size = new System.Drawing.Size(IMAGE_WIDTH, IMAGE_HEIGHT);<br />
PicBoxes[row, col].Image = image_arr[type];<br />
PicBoxes[row, col].Location = new System.Drawing.Point(col * IMAGE_WIDTH, row * IMAGE_HEIGHT);<br />
}<br />
<br />
Got any ideas why the image isn't showing up? The Images are there and in the resources folder.
|
|
|
|
|
in draw_image add it to form controls
Form.Controls.Add()
|
|
|
|
|
I typed Form but there was no "Controls" sub program.
|
|
|
|
|
Form is the name of the class. You need the name of the form itself, which you did not provide. Actually, you need to replace Form with this, as you're inside the form.
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 )
|
|
|
|
|
I partly understood what you meant so I put "PicBoxes[row, col].Controls.Add();" but I don't know what to put for Parameters.
|
|
|
|
|
Controls is not a program but member collection.
As I have written before - formName.Collection.Add()
Collection is without ()
|
|
|
|
|
I'm not too familiar with object oriented programming. I'm used to C++ and PHP. I kinda figured out through trial and error but what do I put for the parameter for Add ()?
|
|
|
|
|
your function should looks like this:
private void draw_image(Byte type, int row, int col)
{
PicBoxes[row, col] = new PictureBox();
PicBoxes[row, col].Name = "pictureBox1";
PicBoxes[row, col].Size = new System.Drawing.Size(IMAGE_WIDTH, IMAGE_HEIGHT);
PicBoxes[row, col].Image = image_arr[type];
PicBoxes[row, col].Location = new System.Drawing.Point(col * IMAGE_WIDTH, row * IMAGE_HEIGHT);
this.Controls.Add( PicBoxes[ row, col ] );
}
the bold line is missing in your code.
|
|
|
|
|
It compiles okay but when I run it I get this error:
An unhandled exception of type 'System.ArgumentException' occurred in System.Windows.Forms.dll
Additional information: A circular control reference has been made. A control cannot be owned by or parented to itself.
|
|
|
|
|
You cannot call data.Controls.Add(data), where "data" is any object.
Jeff
|
|
|
|
|
Then what would I put there? The Form? That would make sense I'll try that.
[Edit Nope that didn't work]
|
|
|
|
|
What command are you currently using?
|
|
|
|
|
this.Controls.Add( (PictureBox)PicBoxes[ row, col ] );
if your table is not of type PictureBox.
read documentation to classes which you use. write PictureBox class in google and you will have everything you need
|
|
|
|
|
Sick. Thanks a bunch Ermak!!
|
|
|
|
|
Jordanwb wrote: I'm not too familiar with object oriented programming. I'm used to C++
That's just mind blowing. That also has nothing to do with this, the form has a Controls property, which has an Add method, and if you open your brackets, intellisense will tell you what to put in there.
Jordanwb wrote: I kinda figured out through trial and error
you'd do better to buy a book and work through it
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 )
|
|
|
|
|
is there any way to host a java applet in windows forms without using a WebBrowser control? i'd like this to be as lightweight as possible (ironic as that sounds). i searched the web and couldn't even find an example in native code.
|
|
|
|
|
zildjohn01 wrote: i searched the web and couldn't even find an example in native code.
There may not be any examples. However since all the browser authors did it, it must be possible right? All you have to do is recreate whatever work they all did and presto, you're done.
|
|
|
|
|
led mike wrote: recreate whatever work they all did
why didn't i think of that? this'll be simple! *downloads firefox source code* (sarcasm)
that code doesn't tell me a thing, i don't even know where to start. if i think about it though, didn't sun (and microsoft, and other vm devs) write the browser plugins themselves? meaning instead of just hosting the applet, i'd have to simulate a browser environment...
this might be more work than it's worth...
|
|
|
|
|
zildjohn01 wrote: this might be more work than it's worth...
Duh
|
|
|
|
|
ok that was mean... lol. WebBrowser it is. i guess i'll just SetParent the java window or rewrite the html and strip the ads out
|
|
|
|
|