private void btnOpenImage_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "All Files|*.*|Bitmap Files|*.bmp"; ofd.FileName = ".bmp"; if (DialogResult.OK == ofd.ShowDialog()) { string ext = Path.GetExtension(ofd.FileName); if (ext == ".bmp" || ext == ".jpg" || ext == ".png" || ext == ".tiff") { m_strFileName = ofd.FileName; mTM = ManagedTextureManager.Instance; mD3d = ManagedDirect3D.Instance; m_nImageID = mTM.LoadTexture(m_strFileName, Color.FromArgb (m_clrKey.R, m_clrKey.G, m_clrKey.B).ToArgb ()); decimal width, height; width = mTM.GetTextureWidth(m_nImageID); height = mTM.GetTextureHeight(m_nImageID); bool ok = true; if (width > nudImageWidth.Maximum) { ok = false; MessageBox.Show("Image width value too large, load a smaller image.", "Error", MessageBoxButtons.OK); } else if (width < nudCellWidth.Value) { ok = false; MessageBox.Show("Image width value too small, load a larger image.", "Error", MessageBoxButtons.OK); } if (height > nudImageHeight.Maximum) { ok = false; MessageBox.Show("Image height value too large, load a smaller image.", "Error", MessageBoxButtons.OK); } else if (height < nudCellHeight.Value) { ok = false; MessageBox.Show("Image height value too small, load a larger image.", "Error", MessageBoxButtons.OK); } if (ok) { nudImageWidth.Value = width; nudImageHeight.Value = height; toolStripStatusLabel1.Text = "Image : Loaded -- " + m_strFileName; scaleX = 494f / (float)(mTM.GetTextureWidth(m_nImageID)); scaleY = 424f / (float)(mTM.GetTextureHeight(m_nImageID)); thisScaleX = panel1.Width / (float)(mTM.GetTextureWidth(m_nImageID)); thisScaleY = panel1.Height / (float)(mTM.GetTextureHeight(m_nImageID)); btnKeyClr.Enabled = true; } } } }
public Form1() { InitializeComponent(); version11ToolStripMenuItem.Text += m_strVersionNumber; this.KeyPreview = true; this.Text += " - " + m_strSaveFileName; //splitContainer1.Focus(); ////////////////////////////////////////////////////////////////////////// // set up the timer m_timer = new Timer(); m_timer.Enabled = true; m_timer.Interval = 2; m_timer.Start(); m_timer.Tick += new EventHandler(timer_Tick); ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// // set up the texture mngr & d3d device m_mD3d = ManagedDirect3D.Instance; m_mD3d.InitManagedDirect3D(this.splitContainer1.Panel2, this.splitContainer1.Panel2.Width, this.splitContainer1.Panel2.Height, true, false); m_mTM = ManagedTextureManager.Instance; m_mTM.InitManagedTextureManager(m_mD3d.Device, m_mD3d.Sprite); dotID = m_mTM.LoadTexture("dot.png", 0); ////////////////////////////////////////////////////////////////////////// //Set up input boxes nudAdjustRectHeight.Enabled = false; nudAdjustRectWidth.Enabled = false; nudAdjustRectX.Enabled = false; nudAdjustRectY.Enabled = false; cbLayerMode.SelectedIndex = 0; cbLayer.SelectedIndex = 0; cbShowFlags.Checked = true; cbShowGrid.Checked = true; ////////////////////////////////////////////////////////////////////////// lbCurrentLayer.Text = m_strLayerLabel + "Layer 1"; splitContainer1.Panel2.AutoScrollMinSize = new Size((int)nudMapCellSize.Value * (int)nudMapNumCols.Value, ((int)nudMapCellSize.Value >> 1) * (int)nudMapNumRows.Value); }