|
Hey, thanks for the reply.
I'm currently doing that. What I am wanting to do is actually change the resolution to 1024x768 while the game(app) is running, and then release it back to the desktop defined resolution upon exit.
This is just a simple project while i learn the language, but I would like to keep things simple in that respect and have it change to that reso when I load it. Any ideas, comments, suggestions and/or flames appreciated.
Thanks,
Acidon
|
|
|
|
|
|
Perfect. Thank you very much.
I did search for this type of info but never found anything. I obviously didn't use the right keywords. At any rate, I appreciate the reply. Take care,
Acidon
|
|
|
|
|
Hey
I am trying to make a simple 2d racing game, the wiev is like GTA.
I have som problem with the car handling. I am using this math right now,
double radians;
double tan;
radians = this.Rotation * (Math.PI/180);
tan = Math.Tan(radians);
Position.X = this.CarBox.Location.X + this.Speed;
Position.Y = this.CarBox.Location.Y + (int)(this.Speed * tan);
this.CarBox.Location = Position;
The speed is between 0-20 and the rotation is 0-360 degree.
The car is now driving forward, when im turning the car rotates like it shild and it moves in other direction, but if i turn to much toward 0 degree(UP) och 180(down) then it will flip and disipare from the screan, the y value is then somthing around -32000.
I have also notis that if i drive in around 45 degreee angle it will drive a bit faster hen if i drive forward(right).
Im not that good at math so i hope somone could help me with this.
Best regards
Jimmy
|
|
|
|
|
Snowjim wrote:
radians = this.Rotation * (Math.PI/180);
lol no, what are you doing here? Math.Pi is 180 deg in radians!
[edit] my bad, the code was just lookign a bit confusing, why are you using degrees at all?[edit]
|
|
|
|
|
Snowjim wrote:
tan = Math.Tan(radians);
Snowjim wrote:
The car is now driving forward, when im turning the car rotates like it shild and it moves in other direction, but if i turn to much toward 0 degree(UP) och 180(down) then it will flip and disipare from the screan, the y value is then somthing around -32000.
Thats what you get at the tan graph asimptotes. At pi intervals IIRC (i really should RC). Hence you can deduce that your angle plotting is not correct.
Rt2 = Rx2 + Ry2 , pythagoras. And the resultant (Rt) should be a factor of your time/speed variable.
plot it on a piece of paper and it should all make sense
|
|
|
|
|
What is the best way to specify a directory in an application. The last thing I want is for the application to crash if it is not installed in the directory that is hard coded. I have certain files that I need to read from to setup my App. How can I specify something like [ProgramFilesFolder] in my app to look there for the necessary file. I know this kind of thing is possible with Windows installer projects. What about the App... especially since I'm still writing in debug mode. Once I add the installer, the files will all be moved to a different directory.
thanks in advance
|
|
|
|
|
Use current directory, and make sure u set your apps working folder to that
|
|
|
|
|
Actually, a better way is to use the Application.StartupPath . The current working directory (which you can get using Environment.CurrentDirectory ) is not always the directory into which your application is installed. The Application.StartupPath is.
Also, you can use Environment.GetFolderPath with the various special folders defined in Environment.SpecialFolder to get the path of that folder as defined by the system. For example, while [ProgramFilesFolder] is a Windows Installer property for the "Program Files" older, you can use the Environment.SpecialFolder.ProgramFiles enum member to get the directory using Environment.GetFolderPath .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thank you... that was the answer I was looking for.
|
|
|
|
|
Hi!
I want to lock the mouse to my application with a key-combination. By lock I mean in a way that you can't move the mouse outside the window of my application. I want to unlock the mouse with the same key-combination (e.g. Ctrl+l).
Is that possible? Can anyone help he?
Thanks
Erik
|
|
|
|
|
Hi
you need to call ClipCursor API
BOOL ClipCursor(
CONST RECT *lpRect
);
check MSDN for more info.
|
|
|
|
|
i thought this was a big developer NO-NO!
|
|
|
|
|
Actually, just use the Cursor.Clip property already provided in the .NET FCL.
As far as being a no-no, just make sure you restore the clipping region (the desktop area) after you're done - even in case of error.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
Is there any C# equivalent for SDK function 'MsgWaitForMultipleObjects()'? I want to implement this following c++ code in c#. Which is the right path to follow.
bool CMyClass::MyFun()
{
unsigned threadID;
DWORD waitResult;
MSG msg;
writeSuccess = false;
hThread = (HANDLE)_beginthreadex(NULL, 0,writeThread, NULL,0,&threadID);
if (!hThread)
return false;
waitResult = MsgWaitForMultipleObjects(1, &hThread, FALSE, INFINITE, QS_ALLINPUT);
while (waitResult != WAIT_OBJECT_0)
{
if (waitResult == WAIT_OBJECT_0 + 1)
while (PeekMessage(&msg, NULL,0,0,PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
if (waitResult == WAIT_FAILED)
{
break;
}
waitResult = MsgWaitForMultipleObjects(1, &hThread, FALSE, INFINITE, QS_ALLINPUT);
}
CloseHandle(hThread);
hThread = NULL;
return writeSuccess;
}
I have read about the IMessageFilter interface of Microsoft.Win32 namespace. Is this the right way to proceed on this.
Kindly advise.
Vini
|
|
|
|
|
WaitHandle.WaitOne uses MsgWaitForMultipleObjects. I know this because when it is called on the UI thread messages are still pumped.
|
|
|
|
|
Hi All,
I want to access a web service(methods) from java at runtime.
what are the ways for doing this?
Any Links to some articles on this would be appreciated
Thanks and Regards
Tushar mahajan.
|
|
|
|
|
|
|
G'day
Have a little program that captures mouse movements and displays the form and relative mouse location on labels on the form in real time. It also allows the form to be dragged while the mouse button is pressed. There is also a rich text box which has text in it. The form's transparency key and the rich text box colour are the same so that the rich text box is transparent. There are buttons which set the rich text box's enable property to either true or false.
When the disable button is pressed, the enable property is set to false. This has the effect of allowing the mouse movement to be captured over the rich text box area.
When the enable button is pressed, the enable property is set to true. Now, mouse movement is not captured in the rich text box area.
Basically, things are working as I expect them to. Want I would like to do is to be able to drag the form while the rich text box is enabled or transparent. I know this can be done as there is a program called "DSCLOCK" which does it. It might be using a normal text box or a label. It doesn't matter to me. Just want a way to allow the area to be moved and still be transparent. Thought about trying to capture the mouse movements at a parent level (Windows). Thought that would let me see all mouse movement and then I could sort out which bits I wanted.
Does anyone know how this can be done?
Sorry about the size of this but it will be easier to see what i'm doing if you cut and paste this into a new C# project.
benny
************************************************************
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace RichTextBox
{
///
/// Summary description for Form1.
///
public class Form1 : System.Windows.Forms.Form
{
private int mousePressedX, mousePressedY;
private System.Windows.Forms.RichTextBox rTxt1;
private System.Windows.Forms.Label lblMouseStatus;
private System.Windows.Forms.Label lblMouseLocation;
private System.Windows.Forms.Button btnEnable;
private System.Windows.Forms.Button btnDisable;
private System.Windows.Forms.Button btnExit;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Label lblFormLocation;
private System.Windows.Forms.GroupBox groupBox2;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.btnEnable = new System.Windows.Forms.Button();
this.rTxt1 = new System.Windows.Forms.RichTextBox();
this.btnDisable = new System.Windows.Forms.Button();
this.lblMouseStatus = new System.Windows.Forms.Label();
this.lblMouseLocation = new System.Windows.Forms.Label();
this.btnExit = new System.Windows.Forms.Button();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.lblFormLocation = new System.Windows.Forms.Label();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.SuspendLayout();
//
// btnEnable
//
this.btnEnable.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(192)), ((System.Byte)(192)), ((System.Byte)(255)));
this.btnEnable.Location = new System.Drawing.Point(224, 32);
this.btnEnable.Name = "btnEnable";
this.btnEnable.TabIndex = 0;
this.btnEnable.Text = "enable";
this.btnEnable.Click += new System.EventHandler(this.btnEnable_Click);
//
// rTxt1
//
this.rTxt1.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(255)), ((System.Byte)(128)));
this.rTxt1.Font = new System.Drawing.Font("Comic Sans MS", 18F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.rTxt1.Location = new System.Drawing.Point(24, 24);
this.rTxt1.Name = "rTxt1";
this.rTxt1.Size = new System.Drawing.Size(176, 40);
this.rTxt1.TabIndex = 1;
this.rTxt1.Text = "Rich Text Box";
//
// btnDisable
//
this.btnDisable.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(192)), ((System.Byte)(192)), ((System.Byte)(255)));
this.btnDisable.Location = new System.Drawing.Point(320, 32);
this.btnDisable.Name = "btnDisable";
this.btnDisable.TabIndex = 2;
this.btnDisable.Text = "disable";
this.btnDisable.Click += new System.EventHandler(this.btnDisable_Click);
//
// lblMouseStatus
//
this.lblMouseStatus.Font = new System.Drawing.Font("Comic Sans MS", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.lblMouseStatus.Location = new System.Drawing.Point(32, 40);
this.lblMouseStatus.Name = "lblMouseStatus";
this.lblMouseStatus.Size = new System.Drawing.Size(320, 23);
this.lblMouseStatus.TabIndex = 3;
this.lblMouseStatus.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// lblMouseLocation
//
this.lblMouseLocation.Font = new System.Drawing.Font("Comic Sans MS", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.lblMouseLocation.Location = new System.Drawing.Point(32, 88);
this.lblMouseLocation.Name = "lblMouseLocation";
this.lblMouseLocation.Size = new System.Drawing.Size(320, 23);
this.lblMouseLocation.TabIndex = 4;
this.lblMouseLocation.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// btnExit
//
this.btnExit.BackColor = System.Drawing.Color.Red;
this.btnExit.Location = new System.Drawing.Point(368, 336);
this.btnExit.Name = "btnExit";
this.btnExit.Size = new System.Drawing.Size(32, 23);
this.btnExit.TabIndex = 9;
this.btnExit.Text = "Exit";
this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
//
// groupBox1
//
this.groupBox1.Controls.Add(this.lblFormLocation);
this.groupBox1.Font = new System.Drawing.Font("Comic Sans MS", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.groupBox1.Location = new System.Drawing.Point(24, 88);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(384, 88);
this.groupBox1.TabIndex = 10;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Form location";
//
// lblFormLocation
//
this.lblFormLocation.Font = new System.Drawing.Font("Comic Sans MS", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.lblFormLocation.Location = new System.Drawing.Point(32, 40);
this.lblFormLocation.Name = "lblFormLocation";
this.lblFormLocation.Size = new System.Drawing.Size(320, 23);
this.lblFormLocation.TabIndex = 11;
this.lblFormLocation.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// groupBox2
//
this.groupBox2.Controls.Add(this.lblMouseStatus);
this.groupBox2.Controls.Add(this.lblMouseLocation);
this.groupBox2.Font = new System.Drawing.Font("Comic Sans MS", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.groupBox2.Location = new System.Drawing.Point(24, 184);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(384, 136);
this.groupBox2.TabIndex = 11;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "Mouse";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(192)), ((System.Byte)(192)));
this.ClientSize = new System.Drawing.Size(432, 376);
this.ControlBox = false;
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.btnExit);
this.Controls.Add(this.btnDisable);
this.Controls.Add(this.rTxt1);
this.Controls.Add(this.btnEnable);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Form1";
this.TransparencyKey = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(255)), ((System.Byte)(128)));
this.Load += new System.EventHandler(this.Form1_Load);
this.groupBox1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Form1 dc = new Form1();
dc.Load+= new EventHandler(dc.DigitalClock_Load);
Application.Run(new Form1());
}
private void DigitalClock_Load(object sender, EventArgs e)
{
}
private void btnEnable_Click(object sender, System.EventArgs e)
{
rTxt1.Enabled = true;
}
private void btnDisable_Click(object sender, System.EventArgs e)
{
rTxt1.Enabled = false;
} // end of button off click
private void Form1_MouseEnter(object sender, System.EventArgs e)
{
lblMouseStatus.Text = "inside";
lblFormLocation.Text = Location.X + " " + Location.Y;
} // end of digitalClock_MouseEnter
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
int mouseX = (e.X);
int mouseY = (e.Y);
int movementX, movementY;
int currentX = Location.X;
int currentY = Location.Y;
lblMouseLocation.Text = e.X + " " + e.Y;
movementX = mouseX - mousePressedX;
movementY = mouseY - mousePressedY;
int newX = (int)(currentX + movementX);
int newY = (int)(currentY + movementY);
if (newX < 0) newX = 0;
if (newY < 0) newY = 0;
if (lblMouseStatus.Text == "pressed")
{
// This is the drag condition
Location = new Point(newX, newY);
}
lblFormLocation.Text = Location.X + " " + Location.Y;
Invalidate();
} // end of digitalClock_MouseMove
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if (lblMouseStatus.Text == "inside" | lblMouseStatus.Text == "up")
{
lblMouseStatus.Text = "pressed";
lblMouseLocation.Text = e.X + " " + e.Y;
mousePressedX = (e.X);
mousePressedY = (e.Y);
}
lblFormLocation.Text = Location.X + " " + Location.Y;
} // end of digitalClock_MouseDown
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
lblMouseStatus.Text = "up"; // always unpress
lblFormLocation.Text = Location.X + " " + Location.Y;
} // end of digitalClock_MouseUp
private void Form1_MouseLeave(object sender, System.EventArgs e)
{
lblMouseStatus.Text = "outside";
lblFormLocation.Text = Location.X + " " + Location.Y;
}
private void Form1_Load(object sender, System.EventArgs e)
{
MouseEnter += new EventHandler(Form1_MouseEnter);
MouseMove += new MouseEventHandler(Form1_MouseMove);
MouseDown += new MouseEventHandler(Form1_MouseDown);
MouseUp += new MouseEventHandler(Form1_MouseUp);
MouseLeave += new EventHandler(Form1_MouseLeave);
rTxt1.Enabled = false;
this.Enabled = true;
}
private void btnExit_Click(object sender, System.EventArgs e)
{
this.Close();
} // end of digitalClock_MouseLeave
}
}
|
|
|
|
|
Take a look at the Control.Capture property. You could capture the mouse and receive notification messages while another control - or even another application, so make sure you use Control.PointToClient to convert the coordinates relative to your control - has the mouse over it.
I don't know anything about DSCLOCK, but I'm guessing it uses system hooks, which is another way to do it, but should be a last resort - especially if this is just necessary in your application.
That said, you can use an IMessageFilter which acts as an application hook, passing all messages that get posted to your message pump (queue) through it giving you a chance to process. See the documentation for this interface, as well as the Application.AddMessageFilter method document in the .NET Framework SDK.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath
Thanks again. Your comments are sufficient for me to sort this out now.
benny
|
|
|
|
|
Hi guys, I've two panels on my WinForm, one is docked to the left of the container and the other at the bottom. Assume that there are no more controls on the form. Now sometimes these panels are docked to the container (i.e. a WinForm) as
+-----------+
| |
| panelLeft +----------------------+
| | panelBottom |
+-----------+----------------------+
and sometimes as
+-----------+
| |
| panelLeft |
| |
+-----------+----------------------+
| panelBottom |
+----------------------------------+
I want to know why? Isn't there any way of making it sure as how these Panels will be docked in RELEASE version.
Plz do reply,
Gurmeet BTW, can Google help me search my lost pajamas?
My Articles: HTML Reader C++ Class Library, Numeric Edit Control
|
|
|
|
|
I think you have to go to your InitializeComponent() and at the end of it see which one added to Control propoerty of your form.
Mazy
"One who dives deep gets the pearls,the burning desire for realization brings the goal nearer." - Babuji
|
|
|
|
|
Both of those panel controls are being added to the Controls property of the form in InitializeComponent() . Whatz the point by the way?
Gurmeet BTW, can Google help me search my lost pajamas?
My Articles: HTML Reader C++ Class Library, Numeric Edit Control
|
|
|
|
|