使用C#中的按钮组合框(下拉链接框)? [英] Combo Box (Drop down link box) with a button in C#?

查看:126
本文介绍了使用C#中的按钮组合框(下拉链接框)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用C#中的Windows窗体应用程序中的提交按钮对视觉工作室2013中的组合框(下拉链接框)进行编码。



这是我想要的只是在c#中 - http://www.itechies.net/tutorials/jscript/jsexample.php-pid-combo.htm



我必须在我的应用程序上节省空间,这将是最好的路线。

从列表框中选择后,单击按钮,它将加载一个包含所选项目的新网页。



编辑:

这是现在的代码,它仍然无法正常工作。使用;(this.DropDownList1.SelectedValue)dropdownList1获取错误。



How do you code a Combo Box (Drop down link box) with a submit button in windows form application in C#, in visual studios 2013.

This is what I want exactly but in c# - http://www.itechies.net/tutorials/jscript/jsexample.php-pid-combo.htm

I have to save space on my application, this would be the best route.
After selecting from the list box, click on the button and it would load a new webpage with the item selected.


This is the code now, and Its still not working. Getting errors with "(this.DropDownList1.SelectedValue) " dropdownList1 getting errors.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
 
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            // set this.FormBorderStyle to None here if needed
            // if set to none, make sure you have a way to close the form!
        }
        protected override void WndProc(ref Message m)
        {
            base.WndProc(ref m);
            if (m.Msg == WM_NCHITTEST)
                m.Result = (IntPtr)(HT_CAPTION);
        }
 
        private const int WM_NCHITTEST = 0x84;
        private const int HT_CLIENT = 0x1;
        private const int HT_CAPTION = 0x2;
 
        private void Form1_Load(object sender, EventArgs e)
        {
 
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            {
                switch (this.DropDownList1.SelectedValue) 
                {
                    case "Google":
                        this.Response.Redirect("http://www.google.com");
                        break;
                    case "Yahoo":
                        this.Response.Redirect("http://www.yahoo.com");
                        break;
                    case "Codeproject":
                        this.Response.Redirect("http://www.codeproject.com");
                        break;
                }
            }
        }
 
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
 
        }
    }
}





编辑:

我对此非常困惑,我试过但这没有成功......我知道它完全错了,有谁知道如何解决这个问题。我有一个有三个网站的combobox1,我有一个按钮提交你在combobox1中选择的内容,请用c#而不是任何其他语言。如果你知道如何解决这个问题,请提前致谢。




I'm very confused with this, I tried this but no success...I know its totally wrong, does anyone know how to solve this. I have a combobox1 that has three websites in it, and I have a button that submits what you pick in the combobox1, in c# not any other language please. Thanks in advance if you know how to solve this.

private void button1_Click(object sender, EventArgs e)
        {
            {

                switch (this.comboBox1.Text)
                {
                    case "Google":
                        this.comboBox1("http://www.google.com");
                        break;
                    case "Yahoo":
                        this.comboBox1("http://www.yahoo.com");
                        break;
                    case "Codeproject":
                        this.comboBox1("http://www.codeproject.com");
                        break;
                }
            }
        }

推荐答案

在Javascript中,你可以使用

In Javascript, you can use either
window.location="http://www.MyWebSite.org/some_URL_taken_from_the_selected_item"
// or
window.navigate("http://www.MyWebSite.org/some_other_URL_taken_from_the_selected_item");



您如何计算URL取决于您。您可以阅读相关控件的属性,或者根据您的设计计算索引是带URL的数组,等等。



-SA


How you calculate the URL is up to you. You can read the value property of the control in question, or calculate the index is some array with URL, anything like that, depending on your design.

—SA


试试这个:
aspx中的


Try this:
in aspx:
<asp:dropdownlist id="DropDownList1" runat="server" xmlns:asp="#unknown">
       <asp:listitem>Google</asp:listitem>
       <asp:listitem>Yahoo</asp:listitem>
       <asp:listitem>Codeproject</asp:listitem>
   </asp:dropdownlist>
   <asp:button id="Button1" runat="server" onclick="Button1_Click" text="Button" xmlns:asp="#unknown" />





代码背后:





in code behind:

protected void Button1_Click(object sender, EventArgs e)
       {
           switch (this.DropDownList1.SelectedValue)
           {
               case "Google":
                   this.Response.Redirect("http://www.google.com");
                   break;
               case "Yahoo":
                   this.Response.Redirect("http://www.yahoo.com");
                   break;
               case "Codeproject":
                   this.Response.Redirect("http://www.codeproject.com");
                   break;
           }
       }


这篇关于使用C#中的按钮组合框(下拉链接框)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆