Delphi7中实现单击Form1中的按钮,弹出Form2并进行Form2中的下一步操作?!

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Delphi7中实现单击Form1中的按钮,弹出Form2并进行Form2中的下一步操作?!相关的知识,希望对你有一定的参考价值。

首先,一定要是Delphi7的编程环境,什么C/C++什么的不要来搞灰机了!!
举个详细一点的例子:
1. Form1中有一个Button,其Caption值为“计算面积”,单击后弹出Form2。
2. 在Form2中进行输入,和计算的其他操作。
3. 单击Form2中的“退出”Button退回到Form1。

现在请教第1步和第3步如何实现!!谢谢!!

参考技术A 1.form2.showmodal

3.button.click事件写
modalresult:=mrok;

太简单的问题啊。
参考技术B 可以远程QQ345224297

抽屉打开并单击底部导航按钮时出现错误

【中文标题】抽屉打开并单击底部导航按钮时出现错误【英文标题】:Getting error when Drawer open and Click on Bottom Navigation button 【发布时间】:2020-03-09 15:35:40 【问题描述】:

我是 Flutter 的新手,下面是代码,如果抽屉打开并且我在“BottomNavigationBar onTap”中的“setState”之前调用了“Navigator.of(context).pop()”,它工作正常。

但如果抽屉未打开且代码运行,它将弹出当前页面,而不是推送带有新正文的重建页面。

class BottomNavigationBarScreen extends StatefulWidget 
  static String routeName = '/bottomnavigationscreen';
  @override
  _BottomNavigationBarScreenState createState() =>
      _BottomNavigationBarScreenState();


class _BottomNavigationBarScreenState extends State<BottomNavigationBarScreen> 
  int _currentIndex = 0;
  final _optionButton = [
    HomeScreen(),
    SearchScreen(),
    ScanScreen(),
    ShoppingCartScreen(),
  ];

  // void onTap(int index) 
  //   setState(() 
  //     _currentIndex = index;
  //   );
  // 

  @override
  Widget build(BuildContext context) 
    GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
    return Scaffold(
      key: _scaffoldKey,
      body: SafeArea(child: _optionButton[_currentIndex]),
      drawer: AppDrawerWidget(),
      bottomNavigationBar: BottomNavigationBar(
          type: BottomNavigationBarType.fixed,
          currentIndex: _currentIndex,
          onTap: (int index) 
            Navigator.of(context).pop();
            setState(() 
              _currentIndex = index;
            );
          ,
          items: [
            BottomNavigationBarItem(
              icon: Icon(
                Icons.home,
                color: Theme.of(context).iconTheme.color,
              ),
              title: Text(''),
            ),
            BottomNavigationBarItem(
                icon: Icon(
                  Icons.search,
                  color: Theme.of(context).iconTheme.color,
                ),
                title: Text('')),
            BottomNavigationBarItem(
                icon: Icon(
                  IconData(59392, fontFamily: 'icons'),
                  color: Theme.of(context).iconTheme.color,
                ),
                title: Text('')),
            BottomNavigationBarItem(
                icon: Icon(
                  Icons.shopping_cart,
                  color: Theme.of(context).iconTheme.color,
                ),
                title: Text('')),
          ]),
    );
  

【问题讨论】:

可以通过_scaffoldKey.currentState.isDrawerOpen属性检查抽屉是否打开 【参考方案1】:

您可以使用_scaffoldKey.currentState.isDrawerOpen检查抽屉是否打开 在您的情况下,您不需要Navigator.of(context).pop();,除非您的AppDrawerWidget 中有特殊操作 当抽屉打开时,点击抽屉外部会自动关闭抽屉 您可以在下面复制粘贴运行完整代码

代码sn-p

onTap: (int index) 
            if (_scaffoldKey.currentState.isDrawerOpen) 
              Navigator.of(context).pop();
            
            print("onTap");
            setState(() 
              _currentIndex = index;
            );
          ,

工作演示

完整代码

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget 
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) 
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        // This is the theme of your application.
        //
        // Try running your application with "flutter run". You'll see the
        // application has a blue toolbar. Then, without quitting the app, try
        // changing the primarySwatch below to Colors.green and then invoke
        // "hot reload" (press "r" in the console where you ran "flutter run",
        // or simply save your changes to "hot reload" in a Flutter IDE).
        // Notice that the counter didn't reset back to zero; the application
        // is not restarted.
        primarySwatch: Colors.blue,
      ),
      home: BottomNavigationBarScreen(),
    );
  



class BottomNavigationBarScreen extends StatefulWidget 
  static String routeName = '/bottomnavigationscreen';
  @override
  _BottomNavigationBarScreenState createState() =>
      _BottomNavigationBarScreenState();


class _BottomNavigationBarScreenState extends State<BottomNavigationBarScreen> 
  int _currentIndex = 0;
  final _optionButton = [
    HomeScreen(),
    SearchScreen(),
    ScanScreen(),
    ShoppingCartScreen(),
  ];

  // void onTap(int index) 
  //   setState(() 
  //     _currentIndex = index;
  //   );
  // 

  @override
  Widget build(BuildContext context) 
    GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
    return Scaffold(
      key: _scaffoldKey,
      appBar: AppBar(
        title: Text("Listen to Drawer Open / Close Example"),
      ),
      body: SafeArea(child: _optionButton[_currentIndex]),
      drawer: AppDrawerWidget(),
      bottomNavigationBar: BottomNavigationBar(
          type: BottomNavigationBarType.fixed,
          currentIndex: _currentIndex,
          onTap: (int index) 
            if (_scaffoldKey.currentState.isDrawerOpen) 
              Navigator.of(context).pop();
            
            print("onTap");
            setState(() 
              _currentIndex = index;
            );
          ,
          items: [
            BottomNavigationBarItem(
              icon: Icon(
                Icons.home,
                color: Theme.of(context).iconTheme.color,
              ),
              title: Text(''),
            ),
            BottomNavigationBarItem(
                icon: Icon(
                  Icons.search,
                  color: Theme.of(context).iconTheme.color,
                ),
                title: Text('')),
            BottomNavigationBarItem(
                icon: Icon(
                  IconData(59392, fontFamily: 'icons'),
                  color: Theme.of(context).iconTheme.color,
                ),
                title: Text('')),
            BottomNavigationBarItem(
                icon: Icon(
                  Icons.shopping_cart,
                  color: Theme.of(context).iconTheme.color,
                ),
                title: Text('')),
          ]),
    );
  


class AppDrawerWidget extends StatefulWidget 
  @override
  _AppDrawerWidgetState createState() => _AppDrawerWidgetState();


class _AppDrawerWidgetState extends State<AppDrawerWidget> 

  @override
  void initState() 
    super.initState();
    print("open");
  

  @override
  void dispose() 
    print("close");
    super.dispose();
  

  @override
  Widget build(BuildContext context) 
    return Drawer(
      child: Column(
        children: <Widget>[
          Text("test1"),
          Text("test2"),
          Text("test3"),
        ],
      ),
    );
  


class HomeScreen extends StatelessWidget 
  @override
  Widget build(BuildContext context) 
    return Text("HomeScreen");
  


class SearchScreen extends StatelessWidget 
  @override
  Widget build(BuildContext context) 
    return Text("SearchScreen");
  


class ScanScreen extends StatelessWidget 
  @override
  Widget build(BuildContext context) 
    return Text("ScanScreen");
  


class ShoppingCartScreen extends StatelessWidget 
  @override
  Widget build(BuildContext context) 
    return Text("ShoppingCartScreen");
  

【讨论】:

【参考方案2】:

添加一个检查以查看导航抽屉是否打开,如果它打开然后弹出它。

例如:if(navigationDrawerOpen) Navigator.pop(context);

【讨论】:

以上是关于Delphi7中实现单击Form1中的按钮,弹出Form2并进行Form2中的下一步操作?!的主要内容,如果未能解决你的问题,请参考以下文章

delphi 如何在两个窗体间切换

delphi 窗体问题

delphi 对窗体中的控件进行遍历

delphi7 中如何点击菜单项弹出新窗体

怎样在C#中实现父窗体向子窗体传值和子窗体向父窗体传值

有关于winform的 点击主窗体的按钮隐藏子窗体?