使用 C# 开发智能手机软件:推箱子(十六)

2024-08-29 23:32

本文主要是介绍使用 C# 开发智能手机软件:推箱子(十六),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

这是“ 使用 C# 开发智能手机软件:推箱子 ” 系列文章的第十六篇。在这篇文章中,介绍 Window/ConfigDlg.cs 源程序文件。这个源程序文件包含 ConfigDlg 类,该类继承自 System.Windows.Forms.Form 类,表示推箱子的“配置”对话框。如下图所示:



    下面是 Window/ConfigDlg.Designer.cs 的源程序的部分代码:

namespace  Skyiv.Ben.PushBox.Window
{
  partial 
class  ConfigDlg
  {
    
private   void  InitializeComponent()
    {
        
//  注意:省略了一些代码
      
      
this .btnSave.DialogResult  =  System.Windows.Forms.DialogResult.OK;
      
this .btnCancel.DialogResult  =  System.Windows.Forms.DialogResult.Cancel;
      
this .btnAdd.Click  +=   new  System.EventHandler( this .btnAdd_Click);
      
this .btnDelete.Click  +=   new  System.EventHandler( this .btnDelete_Click);
      
this .btnUp.Click  +=   new  System.EventHandler( this .btnUp_Click);
      
this .btnDown.Click  +=   new  System.EventHandler( this .btnDown_Click);
    }

    
private  System.Windows.Forms.ListBox lbxGroup;
    
private  System.Windows.Forms.TextBox tbxGroup;
    
private  System.Windows.Forms.Button btnSave;
    
private  System.Windows.Forms.Button btnCancel;
    
private  System.Windows.Forms.Button btnAdd;
    
private  System.Windows.Forms.Button btnDelete;
    
private  System.Windows.Forms.Button btnUp;
    
private  System.Windows.Forms.Button btnDown;
  }
}

下面是 ConfigDlg.cs 的源程序代码:

 1  using  System;
 2  using  System.Windows.Forms;
 3 
 4  namespace  Skyiv.Ben.PushBox.Window
 5  {
 6     ///   <summary>
 7     ///  “配置”对话框
 8     ///   </summary>
 9     public  partial  class  ConfigDlg : Form
10    {
11       public  ConfigDlg( bool  isTopMost)
12      {
13        InitializeComponent();
14        TopMost  =  isTopMost;
15      }
16 
17       public   string [] Groups
18      {
19         get
20        {
21           string [] groups  =   new   string [lbxGroup.Items.Count];
22           for  ( int  i  =   0 ; i  <  lbxGroup.Items.Count; i ++ ) groups[i]  =  lbxGroup.Items[i].ToString();
23           return  groups;
24        }
25         set
26        {
27           if  (value  !=   null )
28          {
29            lbxGroup.BeginUpdate();
30             foreach  ( string  group  in  value) lbxGroup.Items.Add(group);
31            lbxGroup.EndUpdate();
32             if  (lbxGroup.Items.Count  >   0 ) lbxGroup.SelectedIndex  =   0 ;
33          }
34        }
35      }
36 
37       private   void  btnAdd_Click( object  sender, EventArgs e)
38      {
39         string  s  =  tbxGroup.Text.Trim();
40         if  (s.Length  ==   0 return ;
41         int  idx  =  lbxGroup.SelectedIndex;
42         if  (idx  <   0 )
43        {
44          lbxGroup.Items.Add(s);
45          idx  =  lbxGroup.Items.Count  -   1 ;
46        }
47         else  lbxGroup.Items.Insert(idx, s);
48        lbxGroup.SelectedIndex  =  idx;
49      }
50 
51       private   void  btnDelete_Click( object  sender, EventArgs e)
52      {
53         int  idx  =  lbxGroup.SelectedIndex;
54         if  (idx  <   0 return ;
55        lbxGroup.Items.RemoveAt(idx);
56         if  (lbxGroup.Items.Count  <=   0 return ;
57        lbxGroup.SelectedIndex  =  (idx  <  lbxGroup.Items.Count)  ?  idx : (idx  -   1 );
58      }
59 
60       private   void  btnUp_Click( object  sender, EventArgs e)
61      {
62         int  idx  =  lbxGroup.SelectedIndex;
63         if  (idx  <   1 return ;
64        lbxGroup.Items.Insert(idx  -   1 , lbxGroup.SelectedItem);
65        lbxGroup.Items.RemoveAt(idx  +   1 );
66        lbxGroup.SelectedIndex  =  idx  -   1 ;
67      }
68 
69       private   void  btnDown_Click( object  sender, EventArgs e)
70      {
71         int  idx  =  lbxGroup.SelectedIndex;
72         if  (idx  <   0   ||  idx  >=  lbxGroup.Items.Count  -   1 return ;
73        lbxGroup.Items.Insert(idx  +   2 , lbxGroup.SelectedItem);
74        lbxGroup.Items.RemoveAt(idx);
75        lbxGroup.SelectedIndex  =  idx  +   1 ;
76      }
77    }
78  }

这篇关于使用 C# 开发智能手机软件:推箱子(十六)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1119162

相关文章

基于 Cursor 开发 Spring Boot 项目详细攻略

《基于Cursor开发SpringBoot项目详细攻略》Cursor是集成GPT4、Claude3.5等LLM的VSCode类AI编程工具,支持SpringBoot项目开发全流程,涵盖环境配... 目录cursor是什么?基于 Cursor 开发 Spring Boot 项目完整指南1. 环境准备2. 创建

Python使用FastAPI实现大文件分片上传与断点续传功能

《Python使用FastAPI实现大文件分片上传与断点续传功能》大文件直传常遇到超时、网络抖动失败、失败后只能重传的问题,分片上传+断点续传可以把大文件拆成若干小块逐个上传,并在中断后从已完成分片继... 目录一、接口设计二、服务端实现(FastAPI)2.1 运行环境2.2 目录结构建议2.3 serv

Spring Security简介、使用与最佳实践

《SpringSecurity简介、使用与最佳实践》SpringSecurity是一个能够为基于Spring的企业应用系统提供声明式的安全访问控制解决方案的安全框架,本文给大家介绍SpringSec... 目录一、如何理解 Spring Security?—— 核心思想二、如何在 Java 项目中使用?——

springboot中使用okhttp3的小结

《springboot中使用okhttp3的小结》OkHttp3是一个JavaHTTP客户端,可以处理各种请求类型,比如GET、POST、PUT等,并且支持高效的HTTP连接池、请求和响应缓存、以及异... 在 Spring Boot 项目中使用 OkHttp3 进行 HTTP 请求是一个高效且流行的方式。

Java使用Javassist动态生成HelloWorld类

《Java使用Javassist动态生成HelloWorld类》Javassist是一个非常强大的字节码操作和定义库,它允许开发者在运行时创建新的类或者修改现有的类,本文将简单介绍如何使用Javass... 目录1. Javassist简介2. 环境准备3. 动态生成HelloWorld类3.1 创建CtC

使用Python批量将.ncm格式的音频文件转换为.mp3格式的实战详解

《使用Python批量将.ncm格式的音频文件转换为.mp3格式的实战详解》本文详细介绍了如何使用Python通过ncmdump工具批量将.ncm音频转换为.mp3的步骤,包括安装、配置ffmpeg环... 目录1. 前言2. 安装 ncmdump3. 实现 .ncm 转 .mp34. 执行过程5. 执行结

Java使用jar命令配置服务器端口的完整指南

《Java使用jar命令配置服务器端口的完整指南》本文将详细介绍如何使用java-jar命令启动应用,并重点讲解如何配置服务器端口,同时提供一个实用的Web工具来简化这一过程,希望对大家有所帮助... 目录1. Java Jar文件简介1.1 什么是Jar文件1.2 创建可执行Jar文件2. 使用java

C#使用Spire.Doc for .NET实现HTML转Word的高效方案

《C#使用Spire.Docfor.NET实现HTML转Word的高效方案》在Web开发中,HTML内容的生成与处理是高频需求,然而,当用户需要将HTML页面或动态生成的HTML字符串转换为Wor... 目录引言一、html转Word的典型场景与挑战二、用 Spire.Doc 实现 HTML 转 Word1

Java中的抽象类与abstract 关键字使用详解

《Java中的抽象类与abstract关键字使用详解》:本文主要介绍Java中的抽象类与abstract关键字使用详解,本文通过实例代码给大家介绍的非常详细,感兴趣的朋友跟随小编一起看看吧... 目录一、抽象类的概念二、使用 abstract2.1 修饰类 => 抽象类2.2 修饰方法 => 抽象方法,没有

SpringBoot 多环境开发实战(从配置、管理与控制)

《SpringBoot多环境开发实战(从配置、管理与控制)》本文详解SpringBoot多环境配置,涵盖单文件YAML、多文件模式、MavenProfile分组及激活策略,通过优先级控制灵活切换环境... 目录一、多环境开发基础(单文件 YAML 版)(一)配置原理与优势(二)实操示例二、多环境开发多文件版