社区
界面
帖子详情
大家能不能推荐一下一个能加载background bitmap and tick bitmap的较好的类
a_stupid_boy
2002-12-27 09:41:18
以前用CZipSliderCtl,有一些问题想换一个较好用的,谢谢。
...全文
90
1
打赏
收藏
大家能不能推荐一下一个能加载background bitmap and tick bitmap的较好的类
以前用CZipSliderCtl,有一些问题想换一个较好用的,谢谢。
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
1 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
kingcom_xu
2002-12-27
打赏
举报
回复
http://www.codeproject.com/miscctrl/transparentslider.asp
C#_Winform中使用GDI+及双缓冲技术绘制正弦波形图
C#_Winform中使用GDI+及双缓冲技术绘制正弦波形图,移动正弦波形,实时截图,暂停、开始、停止功能。
CPU、内存使用率
根据网友提供代码,逆向画出来的。包含CPU使用率、内存使用率、虚拟内存使用率、内存总量等。数据比较符合靠谱。 ***************************************************************************** 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.Diagnostics; using System.Threading; using System.Runtime.InteropServices; using System.Management; namespace Cpu_Test { public partial class Form1 : Form { public Form1() { InitializeComponent(); } Process[] MyProcesses; Thread td; private void myUser() { ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from Win32_Processor"); foreach (ManagementObject myobject in searcher.Get()) { tssluse.Text = myobject["LoadPercentage"].ToString() + " %"; lblCPU.Text = myobject["LoadPercentage"].ToString() + " %"; mheight = Convert.ToInt32(myobject["LoadPercentage"].ToString()); if (mheight == 100) panel3.Height = 100; CreateImage(); Memory(); } } private void Memory() { Microsoft.VisualBasic.Devices.Computer myInfo = new Microsoft.VisualBasic.Devices.Computer(); //获取物理内存总量 pbMemorySum.Maximum = Convert.ToInt32(myInfo.Info.TotalPhysicalMemory / 1024 / 1024); pbMemorySum.Value = Convert.ToInt32(myInfo.Info.TotalPhysicalMemory / 1024 / 1024); lblSum.Text = (myInfo.Info.TotalPhysicalMemory / 1024).ToString(); //获取可用物理内存总量 pbMemoryUse.Maximum = Convert.ToInt32(myInfo.Info.TotalPhysicalMemory / 1024 / 1024); pbMemoryUse.Value = Convert.ToInt32(myInfo.Info.AvailablePhysicalMemory / 1024 / 1024); lblMuse.Text = (myInfo.Info.AvailablePhysicalMemory / 1024).ToString(); //获取虚拟内存总量 pbVmemorysum.Maximum = Convert.ToInt32(myInfo.Info.TotalVirtualMemory / 1024 / 1024); pbVmemorysum.Value = Convert.ToInt32(myInfo.Info.TotalVirtualMemory / 1024 / 1024); lblVinfo.Text = (myInfo.Info.TotalVirtualMemory / 1024).ToString(); //获取可用虚拟内存总量 pbVmemoryuse.Maximum = Convert.ToInt32(myInfo.Info.TotalVirtualMemory / 1024 / 1024); pbVmemoryuse.Value = Convert.ToInt32(myInfo.Info.AvailableVirtualMemory / 1024 / 1024); lblVuse.Text = (myInfo.Info.AvailableVirtualMemory / 1024).ToString(); } private void Form1_Load(object sender, EventArgs e) { CheckForIllegalCrossThreadCalls = false; MyProcesses = Process.GetProcesses(); //tsslNum.Text = "进程数: "; tsslNum.Text = "进程数: "+ MyProcesses.Length.ToString()+ " CPU使用: "; myUser(); } private void timer1_
Tick
(object sender, EventArgs e) { Control.CheckForIllegalCrossThreadCalls = false; MyProcesses = Process.GetProcesses(); tsslNum.Text = "进程数: " + MyProcesses.Length.ToString() + " | CPU使用:"; td = new Thread(new ThreadStart(myUser)); td.Start(); } private void Form1_FormClosed(object sender, FormClosedEventArgs e) { if (td != null) { td.Abort(); } } int mheight = 0; private void CreateImage() { int i = panel3.Height / 100;
Bitmap
image = new
Bitmap
(panel3.Width, panel3.Height); Graphics g = Graphics.FromImage(image); g.Clear(Color.Green); SolidBrush mybrush = new SolidBrush(Color.Lime); g.FillRectangle(mybrush, 0, panel3.Height - mheight * i, 26, mheight * i); panel3.
Background
Image = image; } } }
纯代码绘制漂亮特效动画按钮
Imports System.ComponentModel _ Public Class DSButton Private _ButtonColor As Color = Color.White Private SF As New System.Drawing.StringFormat Private _Text As String Public Property ButtonColor As Color Get Return _ButtonColor End Get Set(ByVal value As Color) _ButtonColor = value MakeRoundedRect(RoundRectValue, Me, Color.FromArgb(255, ButtonColor.R / 255 * 50, ButtonColor.G / 255 * 50, ButtonColor.B / 255 * 50)) End Set End Property Public Property RoundRectValue As Integer = 10 Private nIndex As Integer = 0 Private IsMouseEnter As Boolean = False Public Property IsShowAnimate As Boolean = False Public Property ButtonText As String Get Return _Text End Get Set(ByVal value As String) _Text = value MakeRoundedRect(RoundRectValue, Me, Color.FromArgb(255, ButtonColor.R / 255 * 50, ButtonColor.G / 255 * 50, ButtonColor.B / 255 * 50)) End Set End Property Private _TextColor As Color = Color.White Public Property TextColor As Color Get Return _TextColor End Get Set(ByVal value As Color) _TextColor = value MakeRoundedRect(RoundRectValue, Me, Color.FromArgb(255, ButtonColor.R / 255 * 50, ButtonColor.G / 255 * 50, ButtonColor.B / 255 * 50)) End Set End Property Private Sub DSButton_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load SetStyle(ControlStyles.UserPaint, True) SetStyle(ControlStyles.AllPaintingInWmPaint, True) SetStyle(ControlStyles.ResizeRedraw, True) SetStyle(ControlStyles.Selectable, True) SF.LineAlignment = StringAlignment.Center SF.Alignment = StringAlignment.Center MakeRoundedRect(RoundRectValue, Me, Color.FromArgb(255, ButtonColor.R / 255 * 50, ButtonColor.G / 255 * 50, ButtonColor.B / 255 * 50)) End Sub Private Sub MakeRoundedRect(ByVal Rounded As Integer, ByVal Ct As Control, ByVal ButtonColor As Color) If Ct.
Background
Image IsNot Nothing Then Ct.
Background
Image.Dispose() Ct.
Background
Image = New
Bitmap
(Ct.Width, Ct.Height) Dim WW, HH As Integer WW = Ct.Width - 1 HH = Ct.Height - 1 Using G As Graphics = Graphics.FromImage(Ct.
Background
Image) G.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias G.TextRenderingHint = Drawing.Text.TextRenderingHint.ClearTypeGridFit Using Gp As New Drawing2D.GraphicsPath Gp.AddArc(New Rectangle(0, 0, Rounded, Rounded), 180, 90) Gp.AddArc(New Rectangle(WW - Rounded, 0, Rounded, Rounded), -90, 90) Gp.AddArc(New Rectangle(WW - Rounded, HH - Rounded, Rounded, Rounded), 0, 90) Gp.AddArc(New Rectangle(0, HH - Rounded, Rounded, Rounded), 90, 90) Gp.AddLine(New Point(0, HH - Rounded), New Point(0, Rounded / 2)) Using Lg As New Drawing2D.LinearGradientBrush(New Point(0, 0), New Point(0, HH), ControlPaint.Dark(ButtonColor, 0.5), ButtonColor) G.FillPath(Lg, Gp) G.DrawPath(Pens.Black, Gp) End Using End Using WW = WW - 3 HH = HH - 3 Using Gp As New Drawing2D.GraphicsPath Gp.AddArc(New Rectangle(3, 3, Rounded, Rounded), 180, 90) Gp.AddArc(New Rectangle(WW - Rounded, 3, Rounded, Rounded), -90, 90) Gp.AddArc(New Rectangle(WW - Rounded, HH / 2 - Rounded - 1, Rounded, Rounded), 0, 90) Gp.AddArc(New Rectangle(3, HH / 2 - Rounded - 1, Rounded, Rounded), 90, 90) Using Lg As New Drawing2D.LinearGradientBrush(New Point(0, 0), New Point(0, HH / 2), Color.FromArgb(220, 255, 255, 255), Color.FromArgb(50, 255, 255, 255)) G.FillPath(Lg, Gp) End Using End Using Using Gp As New Drawing2D.GraphicsPath Gp.AddEllipse(New Rectangle(3, HH / 2 + 10, WW, HH / 2)) Using Lg As New Drawing2D.PathGradientBrush(Gp) Lg.CenterColor = Color.FromArgb(150, 255, 255, 255) Lg.SurroundColors = New Color() {Color.Transparent} Gp.FillMode = Drawing2D.FillMode.Winding G.FillPath(Lg, Gp) End Using End Using Try If _Text.Length 0 Then G.DrawString(_Text, Me.Font, New SolidBrush(TextColor), New Rectangle(0, 0, Me.Width, Me.Height), SF) Catch End Try End Using End Sub Private Sub DSButton_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick End Sub Private Sub DSButton_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown If e.Button = MouseButtons.Left Then MakeRoundedRect(RoundRectValue, Me, Color.Black) End If End Sub Private Sub DSButton_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.MouseEnter If DesignMode = False Then IsMouseEnter = True Timer1.Enabled = True End If End Sub Private Sub DSButton_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.MouseLeave If DesignMode = False Then IsMouseEnter = False Timer1.Enabled = True End If End Sub Private Sub DSButton_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp MakeRoundedRect(RoundRectValue, Me, _ButtonColor) End Sub Private Sub DSButton_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.SizeChanged If Me.IsHandleCreated Then MakeRoundedRect(RoundRectValue, Me, ButtonColor) End If End Sub Private Sub Timer1_
Tick
(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.
Tick
Select Case IsMouseEnter Case True If IsShowAnimate = True Then nIndex = IIf(nIndex + 30 >= 225, 255, nIndex + 30) If nIndex >= 255 Then Timer1.Enabled = False Else nIndex = 255 Timer1.Enabled = False End If Case False nIndex = IIf(nIndex - 20 <= 50, 50, nIndex - 20) If nIndex <= 50 Then Timer1.Enabled = False End Select Try MakeRoundedRect(RoundRectValue, Me, Color.FromArgb(255, ButtonColor.R / 255 * nIndex, ButtonColor.G / 255 * nIndex, ButtonColor.B / 255 * nIndex)) Catch End Try End Sub End Class
仿windows关机功能界面
转载同事的测试例子,也许大家可以看看 // MyFade.cpp : implementation file // #include "stdafx.h" #include "MyFade.h" #pragma warning(disable: 4201) #include #pragma comment(lib,"winmm.lib") #pragma warning(default: 4201) #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif #define WC_FADEWND _T("FadeWnd") ///////////////////////////////////////////////////////////////////////////// // CMyFade CMyFade::CMyFade(CWnd* pParent) { // register the window WNDCLASS wndcls; HINSTANCE hInst = AfxGetInstanceHandle(); if (!(::GetClassInfo(hInst, WC_FADEWND, &wndcls))) { // otherwise we need to register a new class wndcls.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW; wndcls.lpfnWndProc = ::DefWindowProc; wndcls.cbClsExtra = 0; wndcls.cbWndExtra = 0; wndcls.hInstance = hInst; wndcls.hIcon = NULL; // no application icon wndcls.hCursor = AfxGetApp()->LoadStandardCursor(IDC_ARROW); wndcls.hbr
Background
= NULL; // no
background
wndcls.lpszMenuName = NULL; // no manu application wndcls.lpszClassName = WC_FADEWND; if (!AfxRegisterClass(&wndcls)) AfxThrowResourceException(); } m_h
Bitmap
= NULL; m_hNew
Bitmap
= NULL; m_pWndLock = NULL; } CMyFade::~CMyFade() { if (m_h
Bitmap
) { DeleteObject(m_h
Bitmap
); m_h
Bitmap
= NULL; } if (m_hNew
Bitmap
) { DeleteObject(m_hNew
Bitmap
); m_hNew
Bitmap
= NULL; } if (m_pWndLock) { m_pWndLock->SetFocus(); } } BEGIN_MESSAGE_MAP(CMyFade, CWnd) //{{AFX_MSG_MAP(CMyFade) ON_WM_PAINT() ON_WM_TIMER() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CMyFade message handlers void CMyFade::FadeScreen(CWnd *pParent) { if(pParent) { CMyFade *pFade=new CMyFade(pParent); if(pFade) { pFade->Create(pParent, CRect(0, 0, 0, 0)); } } } void CMyFade::OnDraw(CDC* pDC) { CRect rc; GetWindowRect(rc); HDC hbmDC=CreateCompatibleDC(pDC->GetSafeHdc()); H
BITMAP
hOldbmp=(H
BITMAP
)::SelectObject(hbmDC, m_hNew
Bitmap
); // 将屏幕位图再输入到屏幕上去 BitBlt(pDC->GetSafeHdc(), 0, 0, rc.Width(), rc.Height(), hbmDC, 0, 0, SRCCOPY); SelectObject(hbmDC, hOldbmp); DeleteObject(hbmDC); } void CMyFade::OnPaint() { CPaintDC dc(this); OnDraw(&dc); } H
BITMAP
CMyFade::CopyScreenTo
Bitmap
(LPRECT lpRect) { HDC hScrDC, hMemDC; // screen DC and memory DC int nX, nY, nX2, nY2; // coordinates of rectangle to grab int nWidth, nHeight; // DIB width and height int xScrn, yScrn; // screen resolution HGDIOBJ hOld
Bitmap
, h
Bitmap
; if (IsRectEmpty(lpRect)) return NULL; hScrDC = CreateDC("DISPLAY", NULL, NULL, NULL); hMemDC = CreateCompatibleDC(hScrDC); xScrn = GetDeviceCaps(hScrDC, HORZRES); yScrn = GetDeviceCaps(hScrDC, VERTRES); nX = lpRect->left; nY = lpRect->top; nX2 = lpRect->right; nY2 = lpRect->bottom; if (nX < 0) nX = 0; if (nY < 0) nY = 0; if (nX2 > xScrn) nX2 = xScrn; if (nY2 > yScrn) nY2 = yScrn; nWidth = nX2 - nX; nHeight = nY2 - nY; h
Bitmap
= CreateCompatible
Bitmap
(hScrDC, nWidth, nHeight); hOld
Bitmap
= SelectObject(hMemDC, h
Bitmap
); // 将屏幕输入到内存DC里面去,再通过SelectObject到位图句柄里面 BitBlt(hMemDC, 0, 0, nWidth, nHeight, hScrDC, nX, nY, SRCCOPY); // 将刚刚得到到的屏幕位图置换出句柄 h
Bitmap
=SelectObject(hMemDC, hOld
Bitmap
); DeleteDC(hScrDC); DeleteDC(hMemDC); return (H
BITMAP
)h
Bitmap
; } BOOL CMyFade::Create(CWnd *pParent, CRect rc) { if (!pParent || !IsWindow(pParent->GetSafeHwnd())) { MessageBox("error1"); return false; } CClientDC dcParent(pParent); if (dcParent.GetDeviceCaps(RASTERCAPS) & RC_PALETTE) { MessageBox("error2"); return FALSE; } GetDesktopWindow()->GetWindowRect(rc); CString szText; GetDesktopWindow()->GetWindowText(szText); if (!CWnd::CreateEx( 0, WC_FADEWND, szText, WS_POPUP | WS_CHILD | WS_VISIBLE, rc, pParent, NULL, NULL)) { MessageBox("error3"); return FALSE; } /* if(pParent!=GetDesktopWindow()) { m_pWndLock=pParent; m_pWndLock->EnableWindow(false); HRGN hRgn=CreateRectRgn(0, 0, 0, 0); int regiontype=m_pWndLock->GetWindowRgn(hRgn); if(regiontype!=ERROR) { MessageBox("error4"); SetWindowRgn(hRgn, false); } DeleteObject(hRgn); } */ m_h
Bitmap
= CopyScreenTo
Bitmap
(rc); SetTimer(1, 2000, NULL); } ////////////////////////////////////////////////////////////////////////// // 核心函数,将屏幕变暗 H
BITMAP
CMyFade::Fade
Bitmap
(H
BITMAP
hBmp, double dfTrans) { H
BITMAP
hRetBmp = NULL; if (hBmp) { HDC hBufferDC = CreateCompatibleDC(NULL); HGDIOBJ hPrevBufObject = SelectObject(hBufferDC, hBmp); HDC hDirectDC = CreateCompatibleDC(NULL); // DC for working if (hDirectDC) {
BITMAP
bm; GetObject(hBmp, sizeof(bm), &bm);
BITMAP
INFO bmInfo; ZeroMemory(&bmInfo,sizeof(bmInfo)); bmInfo.bmiHeader.biSize = sizeof(
BITMAP
INFOHEADER); bmInfo.bmiHeader.biWidth = bm.bmWidth; bmInfo.bmiHeader.biHeight = bm.bmHeight; bmInfo.bmiHeader.biPlanes = 1; bmInfo.bmiHeader.biBitCount = 32; UINT* ptPixels; H
BITMAP
hDirect
Bitmap
= CreateDIBSection(hDirectDC, (
BITMAP
INFO*)&bmInfo, DIB_RGB_COLORS,(void**)&ptPixels, NULL, 0); if (hDirect
Bitmap
) { // 将hDirect
Bitmap
放入hDirectDC中处理 HGDIOBJ hPrevBufDirObject = SelectObject(hDirectDC, hDirect
Bitmap
); // 当前将原hBmp即屏幕的所有像素写入到hDirectDC // 即需要对像素灰度处理的DC中 BitBlt(hDirectDC,0,0,bm.bmWidth,bm.bmHeight,hBufferDC,0,0,SRCCOPY); int iAlpha = (int)(255.0 * dfTrans / 100.0); int nSize = bm.bmWidth * bm.bmHeight; for (int i=0; i> 16; int iSrcG = ptPixels[i] & 0x0000ff00 >> 8; int iSrcB = ptPixels[i] & 0x000000ff; int iGrey = (iSrcR * 54 + iSrcG * 182 + iSrcB * 19) >> 8; COLORREF Col =iGrey ; //RGB(iGrey, iGrey, iGrey) ; ptPixels[i] = RGB( (GetBValue( Col ) * iAlpha + iSrcB * (255 - iAlpha)) >> 8, (GetGValue( Col ) * iAlpha + iSrcG * (255 - iAlpha)) >> 8, (GetRValue( Col ) * iAlpha + iSrcR * (255 - iAlpha)) >> 8 ); } SelectObject(hDirectDC,hPrevBufDirObject); hRetBmp = hDirect
Bitmap
; } DeleteDC(hDirectDC); } SelectObject(hBufferDC, hPrevBufObject); DeleteDC(hBufferDC); } return hRetBmp; } static i=0; void CMyFade::OnTimer(UINT nIDEvent) { CWnd::OnTimer(nIDEvent); CClientDC dc(this); i+=2; if(i>100) { KillTimer(1); return; } DWORD dwStartCount = timeGetTime(); if(m_hNew
Bitmap
) { DeleteObject(m_hNew
Bitmap
); m_hNew
Bitmap
= NULL; } m_hNew
Bitmap
= Fade
Bitmap
(m_h
Bitmap
,(double)i); OnDraw(&dc); DWORD dwEndCount = timeGetTime(); //
tick
counter in milliseconds }
c#拼图游戏
using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; using System.Xml; using System.Text.RegularExpressions; using System.Security.Cryptography; using System.Security.Cryptography.Xml; using System.Xml.Serialization; namespace PinTu { public partial class Form1 : Form { #region 全局变量 Image im;
Bitmap
bm;
Bitmap
empt; ArrayList arrrect = new ArrayList(); //ArrayList emptpt = new ArrayList(); ArrayList arrpic = new ArrayList(); //ArrayList change = new ArrayList(); PictureBox[] pb; Random rand = new Random(); int Picsize; int gzs; int bushu = 0; int bu = 0; int[] a; int[] b; bool isfirst = true; bool canclick = true; string filename = ""; string juhao = ""; string change = "";
Bitmap
bmpg; #endregion public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { button4.Enabled = false; label2.Text = ""; label4.Text = ""; filename = "Autumn.jpg"; int tempi = rand.Next(1, 1001); Readinfo(tempi.ToString()); textBox1.Text = tempi.ToString(); } private void Creatpic(int[] inta) { panel1.Controls.Clear(); im = Image.FromFile(filename); bm = new
Bitmap
(320, 320); Graphics gg = Graphics.FromImage(bm); gg.DrawImage(im, new Rectangle(0, 0, 320, 320)); panel2.
Background
Image = im; pb = new PictureBox[gzs * gzs]; for (int i = 0; i < gzs * gzs; i++) { pb[i] = new PictureBox(); pb[i].Parent = panel1; pb[i].Size = new Size(Picsize, Picsize); pb[i].Location = new Point((i % gzs) * Picsize, (i / gzs) * Picsize); pb[i].BorderStyle = BorderStyle.FixedSingle; pb[i].Name = a[i].ToString(); pb[i].SizeMode = PictureBoxSizeMode.CenterImage;
Bitmap
bmp = new
Bitmap
(Picsize, Picsize); Graphics g = Graphics.FromImage(bmp); g.DrawImage(bm, new Rectangle(0, 0, Picsize, Picsize), (Rectangle)arrrect[inta[i]], GraphicsUnit.Pixel); pb[i].Image = bmp; pb[i].Click += new EventHandler(Picture_Click); if (a[i] == gzs * gzs - 1) { empt = bmp; //pb[i].Image = null; //pb[i].BackColor = Color.Blue; Image img = pb[i].Image; bmpg = new
Bitmap
(img); for (int k = 0; k < bmpg.Width; k++) { for (int j = 0; j < bmpg.Height; j++) { Color bmpcolor = bmpg.GetPixel(k, j); byte A = bmpcolor.A; byte R = bmpcolor.R; byte G = bmpcolor.G; byte B = bmpcolor.B; bmpcolor = Color.FromArgb(128, R, G, B); bmpg.SetPixel(k, j, bmpcolor); } } pb[i].Image = bmpg; } } } private void Picture_Click(object sender, EventArgs e) { if (canclick == false) return; PictureBox pbox = (PictureBox)sender; if (pbox.Image == null) return; Point opt = pbox.Location; Point ptleft = new Point(opt.X - Picsize, opt.Y); Point ptright = new Point(opt.X + Picsize, opt.Y); Point ptup = new Point(opt.X, opt.Y - Picsize); Point ptdown = new Point(opt.X, opt.Y + Picsize); foreach (PictureBox p in panel1.Controls) { if (p.Location == ptleft && p.Image == bmpg) { change += pbox.Name + "$" + p.Name + "|"; pbox.Location = ptleft; p.Location = opt; bushu++; textBox1.Enabled = false; button1.Enabled = false; } if (p.Location == ptright && p.Image == bmpg) { change += pbox.Name + "$" + p.Name + "|"; pbox.Location = ptright; p.Location = opt; bushu++; textBox1.Enabled = false; button1.Enabled = false; } if (p.Location == ptup && p.Image == bmpg) { change += pbox.Name + "$" + p.Name + "|"; pbox.Location = ptup; p.Location = opt; bushu++; textBox1.Enabled = false; button1.Enabled = false; } if (p.Location == ptdown && p.Image == bmpg) { change += pbox.Name + "$" + p.Name + "|"; pbox.Location = ptdown; p.Location = opt; bushu++; textBox1.Enabled = false; button1.Enabled = false; } } label2.Text = "已走的步数:" + bushu.ToString(); if (IsWin()) { foreach (PictureBox p in panel1.Controls) { if (p.Image == bmpg) { p.Image = empt; break; } } Updatainfo(textBox1.Text.Trim()); int tempi = rand.Next(1, 1001); Readinfo(tempi.ToString()); textBox1.Enabled = true; textBox1.Text = tempi.ToString(); bushu = 0; label2.Text = ""; button1.Enabled = true; } } private void Creatrect() { Picsize = 320 / gzs; arrrect.Clear(); Rectangle[] rect = new Rectangle[gzs * gzs]; for (int i = 0; i < gzs * gzs; i++) { rect[i] = new Rectangle((i % gzs) * Picsize, (i / gzs) * Picsize, Picsize, Picsize); arrrect.Add(rect[i]); } } private void button1_Click(object sender, EventArgs e) { try { OpenFileDialog dial = new OpenFileDialog(); dial.Title = "open the file"; dial.Filter = "Image File(*.jpg)|*.jpg"; dial.InitialDirectory = AppDomain.CurrentDomain.BaseDirectory; if (dial.ShowDialog() == DialogResult.OK) { filename = dial.FileName; Creatpic(a); } } catch(Exception ex) { MessageBox.Show(ex.Message); } } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { if (comboBox1.SelectedIndex == 0) gzs = 2; if (comboBox1.SelectedIndex == 1) gzs = 3; if (comboBox1.SelectedIndex == 2) gzs = 4; if (comboBox1.SelectedIndex == 3) gzs = 5; if (!isfirst) { Creatrect(); DaluanPic(); Creatpic(a); } } private void DaluanPic() { //a = new int[gzs * gzs]; int rpt = gzs * gzs - 1; for (int i = 0; i < gzs * gzs; i++) a[i] = i; for (int i = 0; i < 200; i++) { int p = rand.Next(0, 4); switch (p) { case 0: if (rpt % gzs < gzs - 1) { int temp1 = a[rpt + 1]; a[rpt + 1] = a[rpt]; a[rpt] = temp1; rpt = rpt + 1; } break; case 1: if (rpt % gzs > 0) { int temp2 = a[rpt - 1]; a[rpt - 1] = a[rpt]; a[rpt] = temp2; rpt = rpt - 1; } break; case 2: if (rpt > gzs - 1) { int temp3 = a[rpt - gzs]; a[rpt - gzs] = a[rpt]; a[rpt] = temp3; rpt = rpt - gzs; } break; case 3: if (rpt < gzs * (gzs - 1)) { int temp4 = a[rpt + gzs]; a[rpt + gzs] = a[rpt]; a[rpt] = temp4; rpt = rpt + gzs; } break; } } //b = new int[a.Length]; } private bool IsWin() { b = new int[a.Length]; for (int i = 0; i < gzs * gzs; i++) { Point pt = new Point((i % gzs) * Picsize, (i / gzs) * Picsize); foreach (PictureBox picbox in panel1.Controls) { if (picbox.Location == pt) b[i] = Convert.ToInt32(picbox.Name); } } for (int i = 0; i < b.Length; i++) { if (i != b[i]) return false; } return true; } private void button3_Click(object sender, EventArgs e) { change = ""; arrpic.Clear(); bushu = 0; label2.Text = ""; Creatpic(a); //CrRect(); } private void CrRect() { ArrayList alist = new ArrayList(); gzs = 4; a = new int[16]; for (int m = 0; m < 1050; m++) { DaluanPic(); string s = ""; for (int i = 0; i < a.Length; i++) s += a[i].ToString() + "$"; if (!alist.Contains(s)) alist.Add(s); } Saveinfo(alist); MessageBox.Show("ok"); } private void ReadFile(string s) { StreamReader sr = new StreamReader("abc.txt"); string ss = sr.ReadLine(); while (ss != null) { string[] splitstr = ss.Split('#'); string ps = ""; if (splitstr[0] == s) { juhao = ss; ps = splitstr[1]; string[] split = ps.Split('$'); if (Convert.ToInt32(s) > 1000) { gzs = 4; a = new int[16]; } if (Convert.ToInt32(s) <= 1000) { gzs = 3; a = new int[9]; } for (int w = 0; w < split.Length - 1; w++) a[w] = Convert.ToInt32(split[w]); Creatrect(); Creatpic(a); break; } ss = sr.ReadLine(); } sr.Dispose(); } private void textBox1_KeyPress(object sender, KeyPressEventArgs e) { Regex regex = new Regex("^[0-9]*[1-9][0-9]*$"); if (e.KeyChar == 13) { if (textBox1.Text == "") { MessageBox.Show("请选择局号!"); return; } if (!regex.IsMatch(textBox1.Text.Trim())) { MessageBox.Show("您输入的不是整数!"); return; } if (textBox1.Text.Trim().Substring(0, 1) == "0") { MessageBox.Show("第一位数字
不能
为零!"); return; } if (int.Parse(textBox1.Text.Trim()) > 2000) { MessageBox.Show("输入的局号超出了范围!"); return; } button4.Enabled = false; Readinfo(textBox1.Text.Trim()); textBox1.Enabled = false; button1.Enabled = false; change = ""; arrpic.Clear(); } } private void button2_Click(object sender, EventArgs e) { label2.Text = ""; bushu = 0; textBox1.Enabled = true; button1.Enabled = true; } private void Saveinfo(ArrayList a) { XmlDocument xmldoc = new XmlDocument(); try { XmlElement root = null, pic = null, theElme = null; xmldoc.Load("abc.xml"); root = xmldoc.DocumentElement; for (int i = 0; i < a.Count; i++) { pic = xmldoc.CreateElement("Pictrue"); theElme = xmldoc.CreateElement("JS"); theElme.InnerText = (i + 1001).ToString(); pic.AppendChild(theElme); theElme = xmldoc.CreateElement("ID"); theElme.InnerText = a[i].ToString(); pic.AppendChild(theElme); theElme = xmldoc.CreateElement("Scores"); theElme.InnerText = "初次"; pic.AppendChild(theElme); theElme = xmldoc.CreateElement("Author"); theElme.InnerText = "WBJ"; pic.AppendChild(theElme); theElme = xmldoc.CreateElement("Date"); theElme.InnerText = DateTime.Now.ToString("yyyy-MM-dd"); pic.AppendChild(theElme); root.AppendChild(pic); } xmldoc.Save("abc.xml"); } catch(Exception e) { MessageBox.Show(e.Message); } } private void Readinfo(string s) { bu = 0; change = ""; arrpic.Clear(); XmlDocument xmldoc = new XmlDocument(); try { string[] ppl; XmlElement root=null; xmldoc.Load("abc.xml"); root = xmldoc.DocumentElement; XmlNodeList nodeList = root.ChildNodes; foreach (XmlNode xn in nodeList) { if (xn.SelectSingleNode("JS").InnerText == s) { ppl = xn.SelectSingleNode("ID").InnerText.Split('$'); XmlNode ff = xn.SelectSingleNode("Scores"); if (ff.InnerText == "初次") label4.Text = "目前本局最少步数:" + ff.InnerText; else { XmlNode kk = xn.SelectSingleNode("Author"); XmlNode date = xn.SelectSingleNode("Date"); XmlNode ys = xn.SelectSingleNode("Yanshi"); label4.Text = "目前本局最少步数:" + ff.InnerText; label4.Text += "\n纪录创造者:" + kk.InnerText; label4.Text += "\n记录创造日期:" + date.InnerText; if (ys.InnerText != "xyz") button4.Enabled = true; } if (Convert.ToInt32(s) <= 1000) { gzs = 3; a = new int[9]; } else { gzs = 4; a = new int[16]; } for (int w = 0; w < ppl.Length - 1; w++) a[w] = Convert.ToInt32(ppl[w]); Creatrect(); Creatpic(a); break; } } } catch (Exception e) { MessageBox.Show(e.Message); } } private void Updatainfo(string s) { XmlDocument xmldoc = new XmlDocument(); try { XmlElement root = null; xmldoc.Load("abc.xml"); root = xmldoc.DocumentElement; XmlNodeList nodeList = root.ChildNodes; foreach (XmlNode xn in nodeList) { if (xn.SelectSingleNode("JS").InnerText == s) { XmlNode xx = xn.SelectSingleNode("Scores"); XmlNode author = xn.SelectSingleNode("Author"); XmlNode date = xn.SelectSingleNode("Date"); XmlNode yanshn = xn.SelectSingleNode("Yanshi"); if (xx.InnerText != "初次") { int zxbs = Convert.ToInt32(xx.InnerText); if (zxbs > bushu) { Form2 f2 = new Form2(); f2.Text = "您创造了记录,请输入您的名字"; if (f2.ShowDialog() == DialogResult.OK) { author.InnerText = f2.textBox1.Text.Trim(); xx.InnerText = bushu.ToString(); date.InnerText = DateTime.Now.ToString("yyyy-MM-dd"); yanshn.InnerText = change; f2.Close(); } } } else { Form2 f2 = new Form2(); f2.Text = "您创造了记录,请输入您的名字"; if (f2.ShowDialog() == DialogResult.OK) { author.InnerText = f2.textBox1.Text.Trim(); xx.InnerText = bushu.ToString(); date.InnerText = DateTime.Now.ToString("yyyy-MM-dd"); yanshn.InnerText = change; f2.Close(); } } break; } } xmldoc.Save("abc.xml"); } catch (Exception e) { MessageBox.Show(e.Message); } } private void button4_Click(object sender, EventArgs e) { timer1.Start(); canclick = false; button2.Enabled = false; button3.Enabled = false; button4.Enabled = false; XmlDocument xmldoc = new XmlDocument(); XmlElement root = null; xmldoc.Load("abc.xml"); root = xmldoc.DocumentElement; XmlNodeList nodeList = root.ChildNodes; foreach (XmlNode xn in nodeList) { if (xn.SelectSingleNode("JS").InnerText == textBox1.Text.Trim()) { string yshpic = xn.SelectSingleNode("Yanshi").InnerText; string[] picstr = yshpic.Split('|'); for (int j = 0; j < picstr.Length; j++) arrpic.Add(picstr[j]); break; } } } private void FileEncryption() { //RijndaelManaged key = new RijndaelManaged(); //byte[] bytekey=Encoding.Unicode.GetBytes("我心飞扬穿越时空"); //key.Key = bytekey; //XmlDocument xmlDoc = new XmlDocument(); //xmlDoc.PreserveWhitespace = true; //xmlDoc.Load("abc.xml"); //Encrypt } private void timer1_
Tick
(object sender, EventArgs e) { if (bu < arrpic.Count) { string[] picname = arrpic[bu].ToString().Split('$'); foreach (PictureBox p in panel1.Controls) { if (p.Name == picname[0]) { Point ppt = p.Location; foreach (PictureBox pp in panel1.Controls) { if (pp.Name == picname[1]) { p.Location = pp.Location; pp.Location = ppt; } } } } bu++; } else { timer1.Stop(); button2.Enabled = true; button3.Enabled = true; canclick = true; } } } }
界面
15,978
社区成员
115,866
社区内容
发帖
与我相关
我的任务
界面
VC/MFC 界面
复制链接
扫一扫
分享
社区描述
VC/MFC 界面
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章