PanelやPictureBox上をDXライブラリの描画先にしたいと思っているのですが、どうすればできますか?
現在は、
DX.SetUserWindow(this.Handle);
を用いてフォームのウィンドウを描画先にしています。そこで、
DX.SetUserWindow(panel1.Handle);
や
DX.SetUserWindow(pictureBox1.Handle);
でPanel,PictureBoxを描画先にできるかと思ったのですが、デバッグを開始すると、ウィンドウも表示されずに、
すぐに終了してしまいます。尚、エラーは出ていません。
どうすればよいのでしょうか?
C#は学び始めたばかりです。
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;
using DxLibDLL;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
//public Point btnClientCurPos;
IK ik = new IK();
public Form1()
{
IK ik = new IK();
InitializeComponent();
DX.SetUserWindow(pictureBox2.Handle); //DxLibの親ウインドウをこのフォームウインドウにセット
DX.DxLib_Init();
DX.SetDrawScreen(DX.DX_SCREEN_BACK);
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
DX.DxLib_End();
}
public void MainLoop()
{
DX.ClearDrawScreen();
ik.Draw();
DX.ScreenFlip();
ik.btnClientCurPos = this.PointToClient(Cursor.Position);
label1.Text = ik.btnClientCurPos.ToString();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
}
}
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
static class Program
{
/// <summary>
/// アプリケーションのメイン エントリ ポイントです。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Form1 form = new Form1();
form.Show();
while (form.Created) //Application.Runしないで自分でループを作る
{
form.MainLoop();
Application.DoEvents(); //←必要
}
}
}
}