另一种形式的组合盒物品.... [英] Combo-box items in another form....

查看:44
本文介绍了另一种形式的组合盒物品....的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在WPF中制作了两个窗口。首先是Mainwindow.xmal,其中有一个组合框。





i想要从登录到主窗口窗口访问组合框项目



请为此建议代码。





------ ------------------------------

屏幕:

- ----------------------------------

i have made two windows in WPF. first is Mainwindow.xmal in which there is a combobox.


i want to access combo-box items from login to mainwindow window

please suggest code for this.


------------------------------------
Screen:
------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Net.Mail;
using System.Net.NetworkInformation;

<pre lan="c#">
namespace Mail_Bird
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        SmtpClient smtp = new SmtpClient();
        MailMessage mail = new MailMessage();
        Login login = new Login();

        public MainWindow()
        {
            InitializeComponent();
            smtp.UseDefaultCredentials = false;
            smtp.EnableSsl = true;
            
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            mail.Subject = Text_Subject.Text.Trim();
            mail.To.Add(Text_To.Text.Trim());
            mail.From = new MailAddress(Text_From.Text);
            mail.Body = Text_Body.Text;
            mail.IsBodyHtml = true;
            
            smtp.Credentials=new System.Net.NetworkCredential(login.Text_user.Text+"@"+login.Combo1.SelectedItem,login.Text_pass.ToString());

            if (login.Combo1.SelectedItem=="gmail.com")  /* Here it shows green underlining stating that (possible unintended refrence comparison; to get the value comparison,cast the left hand side to string) */
            
{
             
                smtp.Host = "smtp.gmail.com";
                smtp.Port=587;
            }
            try
            {
                
                smtp.Send(mail);
                MessageBox.Show("Mail Sent Successfully !");
               
            }
            catch(Exception ex)
            {
                ex.ToString();
            }



------------------------------ ---------------------

如果条件......

/ *这里显示绿色下划线声明(可能是非预期的参考比较;获取值比较,将左侧投射到字符串)* /


---------------------------------------------------
on if condition...
/* Here it shows green underlining stating that (possible unintended refrence comparison; to get the value comparison,cast the left hand side to string) */

推荐答案

您可以使用持有组合框的项目源。首先声明一个组合框的公共集合。

you can use a global collection that holding the itemsource of combobox. first declare a public collection of combobox .
private observablecollection<string>comboboxObservableCollection;</string>





在选定的组合项目事件中,编写如下代码。





in selected item event of combobox , write the code like below.

comboboxObservableCollection=this.combobox.selecteditem;


这篇关于另一种形式的组合盒物品....的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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