I used openTK control to draw something,but it wass always displaying a white background. WHY?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using OpenTK;
using OpenTK.Graphics.OpenGL;
using OpenTK.Input;
namespace WindowsFormsApplication10
{
public partial class Form1 : Form
{
bool loaded = false;
public Form1()
{
InitializeComponent();
}
private void glControl1_Load(object sender, EventArgs e)
{
loaded = true;
GL.ClearColor(Color.SkyBlue); // Yey! .NET Colors can be used directly!
}
private void glControl1_Resize(object sender, EventArgs e)
{
if (!loaded)
return;
}
private void glControl1_Paint(object sender, PaintEventArgs e)
{
if (!loaded) // Play nice
return;
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
glControl1.SwapBuffers();
}
}
}
Simply, u forgot to add call of glControl1_Paint,
goto properties of that control, open events, on the top inside Appearance add a call.
While using GLControl instead of GameWindow, you should call glControl1.Invalidate() every time you need to display changes.
Related
i have typed like 2 questions based on 1 thing, Making a button follow the cursor, But anyways, Is it possible to make the button right in the center of the cursor instead of being
in the corner left of the cursor? If yes, then can you show me the code?
What i don't want:
What i want:
And here is all the code.
Form1.cs:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
button1.Location = Cursor.Position;
}
private void button1_Click(object sender, EventArgs e)
{
}
}
}
I am building a simple drag and drop game using windows forms. Its like a jigsaw puzzle. I want to drag pictures from one form to another to complete the puzzle. Is there a way to do this with a PictureBox. It seems to be the only property without the AllowDrop function. Source code below.
I want to drag images from the form on the left to the form on the right.
I was following this tutorial but I cannot get my head around it.
C# Drag and Drop from one Picture box into Another
Form Right
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DragDropGame
{
public partial class ChildFormTwo : Form
{
public ChildFormTwo()
{
InitializeComponent();
pictureBox3.DragEnter += pictureBox3_DragEnter;
pictureBox3.DragDrop += pictureBox3_DragDrop;
}
private void pictureBox3_DragDrop(object sender, DragEventArgs e)
{
var bmp = (Bitmap)e.Data.GetData(DataFormats.Bitmap);
pictureBox2.Image = bmp;
}
private void pictureBox3_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.Bitmap))
e.Effect = DragDropEffects.Move;
}
}
}
Form Left
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DragDropGame
{
public partial class ChildFormTwo : Form
{
public ChildFormTwo()
{
InitializeComponent();
pictureBox3.DragEnter += pictureBox3_DragEnter;
pictureBox3.DragDrop += pictureBox3_DragDrop;
}
private void pictureBox3_DragDrop(object sender, DragEventArgs e)
{
var bmp = (Bitmap)e.Data.GetData(DataFormats.Bitmap);
pictureBox2.Image = bmp;
}
private void pictureBox3_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.Bitmap))
e.Effect = DragDropEffects.Move;
}
}
}
I have the following two pieces of code, please take a look at it, I pointed where it is going wrong.
I removed the functions where I call the second window, they do not make sense here.
First, main form, this form calls the second form:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace STP_Design
{
public partial class STP2Main : Form
{
public STP2Main()
{
InitializeComponent();
tabControl1.SelectedTab = tabPageDeviceManager;
}
private void pictureBox1_Click(object sender, EventArgs e)
{
MenuForm MDIMF = new MenuForm();
MDIMF.MdiParent = this;
MDIMF.StartPosition = FormStartPosition.Manual;
MDIMF.Location = new Point(3, 50);
MDIMF.Show();
tabControl1.Visible = false;
}
public void set()
{
tabControl1.Visible = true; // This statement executes, but does not result in anything I'd expect. The debugger tells me the visibility is false.
tabControl1.BringToFront();
}
}
}
and second form, which I close and should update the first form:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace STP_Design
{
public partial class MenuForm : Form
{
public MenuForm()
{
InitializeComponent();
this.BringToFront();
}
private void button1_Click(object sender, EventArgs e)
{
STP2Main stp = new STP2Main();
stp.set();
this.Close();
}
}
}
You're calling the set method on a new version of the main form, rather than on the version you presumably already have displayed to the user.
What you need to do is get the current main form from the MdiParent property of the menu form, and call the method on that instead.
// In menu form
private void button1_Click(object sender, EventArgs e)
{
var mainForm = this.MdiParent as STP2Main;
if (mainForm != null)
mainForm.set();
this.Close();
}
I am creating a simple web-browser reloader program. In my program I am using these controls
axMozillaBrowser,
Button,
progressBar,
TextBox
I am trying to load a web page "5" times. Below is my code that works when i use webBrowser control (an instance of internet explorer)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
while (progressBar1.Value !=5 )
{
webBrowser1.Navigate(textBox1.Text);
while(webBrowser1.ReadyState != webBrowserRedyState.Complete)
{
if (webBrowser1.ReadyState == webBrowserRedyState.Complete)
{
progressBar1.Value =+ 1;
}
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
progressBar1.Maximum = 5;
textBox1.Text = "www.google.com";
}
}
}
This is the code that is not working when I use axMozillaBrowser control (an instance of Mozilla Browser). This doesn't load the web page and it's waiting cursor is just blinking.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
while (progressBar1.Value !=5 )
{
axMozillaBrowser1.Navigate(textBox1.Text);
while(axMozillaBrowser1.ReadyState != MOZILLACONTROLLib.tagREADYSTATE.READYSTATE_COMPLETE)
{
if (axMozillaBrowser1.ReadyState == MOZILLACONTROLLib.tagREADYSTATE.READYSTATE_COMPLETE)
{
progressBar1.Value =+ 1;
}
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
progressBar1.Maximum = 5;
textBox1.Text = "www.google.com";
}
}
}
Does your browser control have Navigated (or something like that) event?
As example, you can use it into simple logic cycle, where your control navigates to first URL in collection, then, when navigation completed, navigate to second URL and next.
upd: sorry, I read it again and can't understand now.
upd2: but I suggest you to find Navigated and Navigating events and NavigationState property.
I have a C# Web Browser, I am trying to access: my.screenname.aol.com for mail, but it won't even load, I don't have much code...as you can see:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace EmailViewer
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
timer1.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
timer1.Enabled = false;
webBrowser1.Navigate("my.screenname.aol.com");
}
}
}
It's worth a shot to try WebBrowser.ScriptErrorsSuppressed Property to true.