Skip to content

NoBorderDemo 项目分析

项目信息

  • 项目名称: NoBorderDemo
  • 下载链接: NoBorderDemo.rar
  • 分析时间: 2026-03-05

文件结构

NoBorderDemo/
├── Extractor_Icon.ico
├── Project1.py
├── Project1.xml
├── Unit1.py
├── Unit1.pydfm
├── Unit1.sct
├── Unit1.sfm

主程序文件: Project1.py

import sys
from glcl import *
from Unit1 import *

def main():
    icon_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "Extractor_Icon.ico")
    if not os.path.exists(icon_path):
        print('Extractor_Icon.ico is missing. Do not delete or rename this file.')
        return
    Application.Initialize()
    Application.Title = 'Project1'
    Application.MainFormOnTaskbar = True
    Application.Icon.LoadFromFile(icon_path)
    MainForm = Form1(Application)
    MainForm.Show()
    FreeConsole()
    Application.Run()
    MainForm.Free()

if __name__ == '__main__':
    main()

单元文件: Unit1.py

# Powered By Python Studio, The best Python GUI IDE to download from glsite.com.
import os
from glcl import *

class Form1(Form):

    def __init__(self, owner):
        self.Button1 = Button(self)
        self.Button2 = Button(self)
        self.Button3 = Button(self)
        self.Panel1 = Panel(self)

        # 从文件加载窗体属性(位置、大小等)
        self.LoadProps(os.path.join(os.path.dirname(os.path.abspath(__file__)), "Unit1.pydfm"))

        # 绑定事件处理函数
        self.Panel1.OnDblClick = self.Panel1DblClick    # 面板双击事件
        self.Button1.OnClick = self.Button1Click        # 按钮1点击事件
        self.Button3.OnClick = self.Button3Click        # 按钮3点击事件
        self.Button2.OnClick = self.Button2Click        # 按钮2点击事件
        self.Panel1.OnMouseDown = self.Panel1MouseDown  # 面板鼠标按下事件

    def Panel1MouseDown(self, Sender, Button, Shift, X, Y):
        """处理面板鼠标按下事件 - 实现窗体拖动"""
        Application.ReleaseCapture()  # 释放鼠标捕获
        # 发送系统命令,实现窗体拖动(0xF012 对应拖动操作)
        self.Perform(WM_SYSCOMMAND, 0xF012, 0)

    def Button2Click(self, Sender):
        """按钮2点击事件 - 关闭窗体"""
        self.Close()

    def Button3Click(self, Sender):
        """按钮3点击事件 - 最小化窗体"""
        self.WindowState = wsMinimized  # 设置窗体状态为最小化

    def Button1Click(self, Sender):
        """按钮1点击事件 - 切换最大化/正常状态"""
        if self.WindowState == wsMaximized:
            # 如果当前是最大化状态,切换到正常状态
            self.Button1.Caption = 'Maximized'  # 更新按钮文本
            self.WindowState = wsNormal        # 设置为正常状态
        else:
            # 如果当前是正常状态,切换到最大化状态
            self.Button1.Caption = 'Normal'    # 更新按钮文本
            self.WindowState = wsMaximized     # 设置为最大化状态
            self.Height = Screen.WorkAreaHeight  # 设置高度为屏幕工作区高度

    def Panel1DblClick(self, Sender):
        """面板双击事件 - 模拟按钮1点击(切换最大化/正常状态)"""
        self.Button1.Click()  # 触发按钮1的点击事件

设计文件: Unit1.sct

def Panel1MouseDown(Sender, Button, Shift, X, Y): 
def Button2Click(Sender): 
def Button3Click(Sender): 
def Button1Click(Sender): 
def Panel1DblClick(Sender): 

设计文件: Unit1.sfm

object Form1: TForm
  Left = 0
  Top = 0
  BorderStyle = bsNone
  Caption = 'Form1'
  ClientHeight = 524
  ClientWidth = 863
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  Position = poScreenCenter
  DesignSize = (
    863
    524)
  TextHeight = 13
  object YSizer1: TYSizer
    Left = 839
    Top = 499
    Height = 17
    Cursor = crSizeAll
    Color = clTeal
    Anchors = [akRight, akBottom]
  end
  object Panel1: TPanel
    Left = 0
    Top = 0
    Width = 863
    Height = 33
    Align = alTop
    BevelOuter = bvNone
    Color = clDarkblue
    ParentBackground = False
    TabOrder = 0
    OnDblClick = Panel1DblClick
    OnMouseDown = Panel1MouseDown
    object Button1: TButton
      Left = 706
      Top = 1
      Width = 75
      Height = 25
      Align = alCustom
      Anchors = [akTop, akRight]
      Caption = 'Maximized'
      TabOrder = 0
      OnClick = Button1Click
    end
    object Button2: TButton
      Left = 781
      Top = 1
      Width = 75
      Height = 25
      Align = alCustom
      Anchors = [akTop, akRight]
      Caption = 'Close'
      TabOrder = 1
      OnClick = Button2Click
    end
    object Button3: TButton
      Left = 631
      Top = 1
      Width = 75
      Height = 25
      Align = alCustom
      Anchors = [akTop, akRight]
      Caption = 'Minimized'
      TabOrder = 2
      OnClick = Button3Click
    end
  end
  object NoBorderForm1: TNoBorderForm
    EnabledShadow = False
    Left = 800
    Top = 472
  end
end

其他文件

  • Extractor_Icon.ico
  • Project1.xml

详细分析

功能概述

GUI组件演示

使用的组件

  • Form1 (TForm)
  • YSizer1 (TYSizer)
  • Panel1 (TPanel)
  • Button1 (TButton)
  • Button2 (TButton)
  • Button3 (TButton)
  • NoBorderForm1 (TNoBorderForm)

技术特点

  • 包含7个GUI组件
  • 定义3个事件处理

窗体属性

  • caption: Minimized
  • height: 524
  • width: 863

代码分析

导入的模块: - import os - from glcl import *

定义的类: - Form1

定义的方法: - init - Panel1MouseDown - Button2Click - Button3Click - Button1Click - Panel1DblClick

事件绑定: - self.Button1.OnClick = self.Button1Click # 按钮1点击事件 - self.Button3.OnClick = self.Button3Click # 按钮3点击事件 - self.Button2.OnClick = self.Button2Click # 按钮2点击事件