GVKun编程网logo

C# – 在ListBox中添加Button(c#list添加元素)

16

在本文中,您将会了解到关于C#–在ListBox中添加Button的新资讯,同时我们还将为您解释c#list添加元素的相关在本文中,我们将带你探索C#–在ListBox中添加Button的奥秘,分析c

在本文中,您将会了解到关于C# – 在ListBox中添加Button的新资讯,同时我们还将为您解释c#list添加元素的相关在本文中,我们将带你探索C# – 在ListBox中添加Button的奥秘,分析c#list添加元素的特点,并给出一些关于(15)各种Button 与排列 OutlineButton,ButtonBar,Expanded,RaisedButton,StadiumBorder,FlatButton.icon、android 实现 ListView 中添加 RaidoButton 单选、Android:解决ExpandableListView中添加button后item项点击事件问题、button.addactionlistener(this)_input button的实用技巧。

本文目录一览:

C# – 在ListBox中添加Button(c#list添加元素)

C# – 在ListBox中添加Button(c#list添加元素)

我正在编写一个带有ListBox的C#App(WinForm),其中包含用户添加的内容.现在,我可以在ListBox下面有一个普通的按钮来删除项目,但是我希望按钮位于内容旁边,因此位于ListBox内部.

像这样:

>内容1 | X
>内容2 | X
> ……
>内容5 | X

问题是我缺乏.NET经验,所以我不知道如何通过所有自动化控件继续实现这一点.我用谷歌搜索了它,但没有得出任何有意义的结果.

任何有关实现此目的的提示,线索或片段都是受欢迎的!

总结

以上是小编为你收集整理的C# – 在ListBox中添加Button全部内容。

如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。

(15)各种Button 与排列 OutlineButton,ButtonBar,Expanded,RaisedButton,StadiumBorder,FlatButton.icon

(15)各种Button 与排列 OutlineButton,ButtonBar,Expanded,RaisedButton,StadiumBorder,FlatButton.icon

效果

至于倒数第二行和倒数第一行的效果为啥一样。。可能是fluttersdk升级了。。之前的api不再生效。。算是留坑!

代码

import ''package:flutter/material.dart'';

class ButtonDemo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final Widget _floatButtonDemo =
        Row(mainAxisAlignment: MainAxisAlignment.center, children: [
      FlatButton(
        onPressed: () {},
        child: Text("FlatButton"),
        splashColor: Colors.grey,
        textColor: Theme.of(context).accentColor,
        color: Colors.black87,
      ),
      FlatButton.icon(
        icon: Icon(Icons.add),
        onPressed: () {},
        label: Text("FlatButton.icon"),
        splashColor: Colors.grey,
        textColor: Theme.of(context).accentColor,
        color: Colors.black87,
      )
    ]);

    final Widget _raisedButtonDemo =
        Row(mainAxisAlignment: MainAxisAlignment.center, children: [
      Theme(
          // data: ThemeData(),
          data: Theme.of(context).copyWith(
              buttonColor: Theme.of(context).accentColor,
              buttonTheme: ButtonThemeData(
                textTheme: ButtonTextTheme.primary,
                // shape: BeveledRectangleBorder(borderRadius: BorderRadius.circular(5.0)),
                shape: StadiumBorder(),
              )),
          child: RaisedButton(
            onPressed: () {},
            child: Text("RaisedButton"),
            splashColor: Colors.grey,
            textColor: Theme.of(context).accentColor,
            // color: Colors.white,
            // textTheme: ButtonTextTheme.primary,
            elevation: 0.0,
          )),
      SizedBox(
        width: 16.0,
      ),
      RaisedButton.icon(
        icon: Icon(Icons.add),
        onPressed: () {},
        label: Text("RaisedButton.icon"),
        splashColor: Colors.grey,
        textColor: Theme.of(context).accentColor,
        elevation: 12.0,
      )
    ]);

    final Widget _outerLineButtonDemo =
        Row(mainAxisAlignment: MainAxisAlignment.center, children: [
      Theme(
          // data: ThemeData(),
          data: Theme.of(context).copyWith(
              buttonColor: Theme.of(context).accentColor,
              buttonTheme: ButtonThemeData(
                textTheme: ButtonTextTheme.primary,
                // shape: BeveledRectangleBorder(borderRadius: BorderRadius.circular(5.0)),
                shape: StadiumBorder(),
              )),
          child: OutlineButton(
            onPressed: () {},
            child: Text("OutlineButton"),
            splashColor: Colors.grey[100],
            textColor: Colors.black,
            borderSide: BorderSide(color: Colors.black),
            highlightedBorderColor: Colors.grey,
            // textTheme: ButtonTextTheme.primary,
          )),
      SizedBox(
        width: 16.0,
      ),
      OutlineButton.icon(
        icon: Icon(Icons.add),
        onPressed: () {},
        label: Text("OutlineButton.icon"),
        splashColor: Colors.grey,
        textColor: Theme.of(context).accentColor,
      )
    ]);

    final Widget _widthOuterLineButton = Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        Container(
          width: 200,
          child: OutlineButton(
            onPressed: () {},
            child: Text("_widthOuterLineButton"),
            splashColor: Colors.grey,
            textColor: Colors.blue,
          ),
        )
      ],
    );
    final Widget _expendOuterLineButton = Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        Expanded(
          child: OutlineButton(
            onPressed: () {},
            child: Text("_expendOuterLineButton"),
            splashColor: Colors.grey,
            textColor: Colors.blue,
          ),
        )
      ],
    );
    final Widget _expend2OuterLineButton = Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        Expanded(
          flex: 1,
          child: OutlineButton(
            onPressed: () {},
            child: Text("权重 for 1"),
            splashColor: Colors.grey,
            textColor: Colors.blue,
          ),
        ),
        SizedBox(
          width: 15,
        ),
        Expanded(
          //权重属性
          flex: 2,
          child: OutlineButton(
            onPressed: () {},
            child: Text("权重 for 2"),
            splashColor: Colors.grey,
            textColor: Colors.blue,
          ),
        )
      ],
    );
    //一行并列行显示的按钮
    final Widget _buttonBar = Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        ButtonBar(
          children: [
            OutlineButton(
              onPressed: () {},
              child: Text("ButtonBar"),
              splashColor: Colors.grey,
              textColor: Colors.blue,
            ),
            OutlineButton(
              onPressed: () {},
              child: Text("ButtonBar"),
              splashColor: Colors.grey,
              textColor: Colors.blue,
            ),
          ],
        )
      ],
    );
    //对刚才的并排中间添加边距
    final Widget _buttonBarPaddingv = Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        Theme(
          data: Theme.of(context).copyWith(
              buttonTheme: ButtonThemeData(
                  padding: EdgeInsets.symmetric(horizontal: 100.0))),
          child: ButtonBar(
            children: [
              OutlineButton(
                onPressed: () {},
                child: Text("ButtonBar"),
                splashColor: Colors.grey,
                textColor: Colors.blue,
              ),
              OutlineButton(
                onPressed: () {},
                child: Text("ButtonBar"),
                splashColor: Colors.grey,
                textColor: Colors.blue,
              ),
            ],
          ),
        )
      ],
    );
    return Scaffold(
      appBar: AppBar(
        title: Text("button Demo"),
        elevation: 0.0,
      ),
      body: Container(
        padding: EdgeInsets.all(16.0),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            _floatButtonDemo,
            _raisedButtonDemo,
            _outerLineButtonDemo,
            _widthOuterLineButton,
            _expendOuterLineButton,
            _expend2OuterLineButton,
            _buttonBar,
            _buttonBarPaddingv
          ],
        ),
      ),
    );
  }
}

 

android 实现 ListView 中添加 RaidoButton 单选

android 实现 ListView 中添加 RaidoButton 单选

import android.app.Activity;

import android.view.LayoutInflater;

import android.view.View;

import android.view.ViewGroup;

import android.widget.BaseAdapter;

import android.widget.CompoundButton;

import android.widget.CompoundButton.OnCheckedChangeListener;

import android.widget.ImageView;

import android.widget.RadioButton;

import android.widget.TextView;

public class RecoverListAdapter extends BaseAdapter {

private LayoutInflater inflater;

int[] backup_record_item_image;

String[] backup_record_item_time;

String[] backup_record_item_to;

Activity activity;

private int temp = -1;

public RecoverListAdapter(Activity context, int[] backup_record_item_image,

String[] backup_record_item_time, String[] backup_record_item_to) {

this.inflater = LayoutInflater.from(context);

this.backup_record_item_image = backup_record_item_image;

this.backup_record_item_time = backup_record_item_time;

this.backup_record_item_to = backup_record_item_to;

this.activity = context;

}

@Override

public int getCount() {

return backup_record_item_time.length;

}

@Override

public Object getItem(int position) {

return position;

}

@Override

public long getItemId(int position) {

return position;

}

@Override

public View getView(int position, View convertView, ViewGroup parent) {

ViewHolder holder;

if (convertView == null) {

holder = new ViewHolder();

convertView = this.inflater.inflate(R.layout.general_recover_list_item, null);

holder.iv = (ImageView) convertView.findViewById(R.id.backup_record_item_image);

holder.tv_time = (TextView) convertView.findViewById(R.id.backup_record_item_time);

holder.tv_to = (TextView) convertView.findViewById(R.id.backup_record_item_to);

holder.radioButton = (RadioButton) convertView

.findViewById(R.id.backup_record_item_btn);

holder.radioButton.setChecked(false);

convertView.setTag(holder);

} else {

holder = (ViewHolder) convertView.getTag();

}

holder.iv.setImageResource(backup_record_item_image[position]);

holder.tv_time.setText(backup_record_item_time[position]);

holder.tv_to.setText(backup_record_item_to[position]);

// 黑体部分为实现单选功能部分

holder.radioButton.setId(position);

holder.radioButton.setOnCheckedChangeListener(new OnCheckedChangeListener() {

@Override

public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {


if (isChecked) {

if (temp != -1) {

RadioButton tempButton = (RadioButton) activity.findViewById(temp);

if (tempButton != null) {

tempButton.setChecked(false);

}

}

temp = buttonView.getId();

}

}

});

if (position == temp) {

holder.radioButton.setChecked(true);

} else {

holder.radioButton.setChecked(false);

}

return convertView;

}

private class ViewHolder {

ImageView iv;

TextView tv_time;

TextView tv_to;

RadioButton radioButton;

}

}


general_recover_list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="fill_parent">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dip"
android:paddingRight="5dip"
android:id="@+id/backup_record_item">
<ImageView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="@drawable/icon"
android:layout_alignParentLeft="true"
android:id="@+id/backup_record_item_image"/>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:orientation="vertical"
android:layout_toRightOf="@+id/backup_record_item_image"
android:id="@+id/backup_record_item_txt">
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="时间"
android:layout_alignTop="@+id/imageView1"
android:layout_alignBottom="@+id/imageView1"
android:id="@+id/backup_record_item_time"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="备份联系人 到"
android:layout_toRightOf="@+id/imageView1"
android:layout_alignTop="@+id/imageView1"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="手机 / 存储卡"
android:layout_toRightOf="@+id/imageView1"
android:layout_alignTop="@+id/imageView1"
android:id="@+id/backup_record_item_to" />
</LinearLayout>
<RadioButton
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"
android:id="@+id/backup_record_item_btn" />

<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:text=""
android:id="@+id/backup_record_item_check" />
</RelativeLayout>
</LinearLayout>

main.xml
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="@+id/recover_items">
<ListView
android:id="@+id/recover_list"
android:cacheColorHint="#00000000"
android:layout_height="match_parent"
android:layout_width="fill_parent"/>
<View
android:id="@+id/recover_footer"
android:layout_width="fill_parent"
android:layout_height="40dip" />
</LinearLayout>

Android:解决ExpandableListView中添加button后item项点击事件问题

Android:解决ExpandableListView中添加button后item项点击事件问题

在ExpandableListView中添加button后item项不能点击,获取不到点击事件。

原因:

button按钮抢占了ExpandableListView的焦点

解决方法:

为button按钮添加android:focusable=false属性,关闭button获取焦点,ExpandableListView中的项目即可点击

button.addactionlistener(this)_input button

button.addactionlistener(this)_input button

大家好,又见面了,我是你们的朋友全栈君。

//首先要在PageLoad()事件中注册属性 protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Button1.Attributes.Add(“onclick”, “return checkSame()”);//为Button1添加onclick()事件 ,Button为服务器控件 }//注意:checkSame()这是一个写在aspx面页的js函数,必须有返回值,为:true 或 false }

//接着写Button1的onclick事件,如果刚才的checkSame()返回为true则招行下面的事件,否则不执行

protected void Button1_Click(object sender, ImageClickEventArgs e) { sqlParameter[] Params = new sqlParameter[2]; Params[0] = dbs.MakeInParams(“@uid”, sqlDbType.VarChar, 10, Session[“Uid”].ToString()); Params[1] = dbs.MakeOutParms(“@Upwd”, sqlDbType.VarChar, 10); if (dbs.ExecuteNonQuery(CommandType.StoredProcedure, “selectPwd”, Params) > 0) { string userPwd = Params[1].Value.ToString(); if (userPwd != this.old_pwd.Text) { Response.Write(“<script>alert(‘原始密码错误!’)</script>”); } else { } } else { ClientScript.RegisterStartupScript(this.GetType(), “”, “<script>alert(‘操作失败!’)</script>”); }

}

//呵呵。。再写一个js试例吧 function checkSame() { var Obj1=document.getElementById (“new_pwd”).value; var Obj2=document.getElementById (“re_new_pwd”).value; if(Obj1!=Obj2) { alert(“两次密码输入不一致!”); document.getElementById(“new_pwd”).focus(); return false; } else { return true; } }

//明白了吗。。这是一个用来判断两次密码输入是否一致的函数

<script language=”javascript”> <!–

///显示某个订单的详细信息,通过一个模态对话框,而且屏幕会变颜色 function ShowOrderDetails(murl) { // var url = “Alarm_add.aspx?ID=”+ murl +””; var Width=”700″; var Height=”500″; // alert(murl); var vDialog=window.showModalDialog(murl,window,”dialogWidth:” + Width + “px;dialogHeight:” + Height + “px;center:yes;status:no;scroll:yes;help:no;”);

window.location.href =window.location.href; } </script>

protected void Button_add_Click(object sender, EventArgs e) { // Response.Write(“<script language=javascript>location=’AddMenu.aspx’;</script>”); string empno = “”; string url = “Alarm_add.aspx?ID=”+ empno+””; // Button_add.Attributes.Add(“onclick”, “return ShowOrderDetails(‘” + url + “‘)”);//为Button1添加onclick()事件 ,Button为服务器控件 ClientScript.RegisterStartupScript(this.GetType(), “”, “<script>ShowOrderDetails(‘” + url + “‘);</script>”); }

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

我们今天的关于C# – 在ListBox中添加Buttonc#list添加元素的分享已经告一段落,感谢您的关注,如果您想了解更多关于(15)各种Button 与排列 OutlineButton,ButtonBar,Expanded,RaisedButton,StadiumBorder,FlatButton.icon、android 实现 ListView 中添加 RaidoButton 单选、Android:解决ExpandableListView中添加button后item项点击事件问题、button.addactionlistener(this)_input button的相关信息,请在本站查询。

本文标签: