给window加样式

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="window.aspx.cs" Inherits="window" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>登录程序</title>
    <style type="text/css" >
    .contain
    {
     width:100%;
     height:100%;
     top:0;
     left :0;
    }
    .center
    {
     position:absolute;
     top:30%;
     left :43%;
     text-align :left ;
    }
    
    </style>
    <link href="ext-2.0.2/resources/css/ext-all.css" rel="stylesheet" type="text/css" />
    <script src="ext-2.0.2/adapter/ext/ext-base.js" type="text/javascript"></script>
    <script src="ext-2.0.2/ext-all-debug.js" type="text/javascript"></script>
    <script type ="text/javascript" >
     Ext.onReady(function (){
         var _window = new Ext.Window({
               layout:"form",
               title:"登 录",
               height:130,
               width:220,
               plain:true ,
               resizable:true ,
               top:100,
               frame:true,
               minimizable:true ,
               maximizable:true ,
               closeAction:"hide",
               buttonAlign:"center",
               bodyStyle:"padding:3px;",
               labelWidth:50,
               defaults:{xtype:"textfield"},
               items:[{fieldLabel:"账 号"},{fieldLabel:"密 码"}],
               buttons:[{text:"确 定"},{text:"取 消",handler:function (){_window .hide();}}]
         });
     _window .applyToMarkup(Ext.DomHelper.append(Ext.getBody(),{
                            tag:"div",
                            cls:"contain",
                            cn:[{
                                 tag:"div",
                                 cls:"center"
                            }]
                          },true).child("div"));
     _window .show();
         
     });
    </script>
</head>
<body>

</body>
</html>

### 创建自定义WPF窗口样式 为了创建具有独特外观的WPF窗口,可以利用XAML的强大功能来设计界面并应用样式。下面是一个简单的例子展示如何实现这一目标。 #### 定义基本结构 首先,在`App.xaml`文件中设置应用程序的主题风格: ```xml <Application.Resources> <!-- Define application-wide styles here --> </Application.Resources> ``` 接着,创建一个新的`Window`类继承自`System.Windows.Window`,用于构建自定义窗口逻辑[^1]。 #### 设计窗口布局 在对应的`.xaml`文件里编写如下代码片段,这会移除默认标题栏,并允许通过拖拽整个客户区移动窗口位置: ```xml <Window x:Class="CustomWindowExample.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="" WindowStyle="None" AllowsTransparency="True" Background="#FFDDEEFF"> <Border CornerRadius="8" BorderBrush="Gray" BorderThickness="1" Padding="5"> <DockPanel LastChildFill="True"> <!-- Add a header that allows dragging the window --> <StackPanel Orientation="Horizontal" DockPanel.Dock="Top" Height="30" VerticalAlignment="Center" MouseLeftButtonDown="TitleBar_MouseLeftButtonDown"> <Image Source="/Images/icon.png" Width="16"/> <TextBlock Text="My Custom Window" Margin="5,0,0,0" FontSize="14" VerticalAlignment="Center"/> <!-- Close button --> <Button Content="✕" Click="CloseButton_Click" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" Width="30" /> </StackPanel> <!-- Main content area goes here --> <ContentPresenter/> </DockPanel> </Border> </Window> ``` 上述代码实现了无边框、可透明度调节的基础框架;顶部包含了一个模拟的标准标题条,其中入了关闭按钮以及支持鼠标左键按下事件触发窗口拖动的功能[^2]。 #### 添加交互行为 对于C#部分,则需处理一些必要的操作如响应点击关闭按钮的动作或是使窗口能够被拖曳: ```csharp private void CloseButton_Click(object sender, RoutedEventArgs e) { this.Close(); } private void TitleBar_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if (e.ChangedButton == MouseButton.Left && e.ClickCount == 1) { DragMove(); // Move the window with mouse drag. } } ``` 此段程序确保了当用户单击左侧鼠标的次数等于一次时,可以通过按住并拖动的方式调整窗口的位置。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值