mertugruul Posted June 6, 2015 Share Posted June 6, 2015 Merhaba. InputBox'da OK veya Cancel tıklandığında bu durumu kontrol ettirmek istiyorum DialogResult'taki gibi. Fakat araştırmama rağmen tatmin edici bilgiler bulamadım. InputBoxResult classını kullanamıyorum bir türlü. Nasıl ulaşabilirim buna ya da nasıl kontrol ettirebilirim InputBox'ı aynı MessageBox'ta ki gibi? http://nuhazginoglu.blogcu.com/c-inputbox-kullanimi/4528678 Şurada InputBoxResult kullanılmış ama nasıl ulaşacağım buna? Referanslarım flan ekli InputBox için onlarda sıkıntı yok. Quote Link to comment Share on other sites More sharing options...
KintaRo Posted June 6, 2015 Share Posted June 6, 2015 C#'da inputbox yok o yüzden referans ekleme ile VB'nin inputbox'unu kullanmak gerekiyor. Ama ben onu sevmiyorum çok çirkin bir görüntüsü var. Onun yerine Form nesnesi ile oluşturulan bir inputbox kullanıyorum: method: public static DialogResult InputBox(string title, string promptText, ref string value) { var form = new Form(); var label = new Label(); var textBox = new TextBox(); var buttonOk = new Button(); var buttonCancel = new Button(); form.Text = title; label.Text = promptText; textBox.Text = value; buttonOk.Text = "OK"; buttonCancel.Text = "Cancel"; buttonOk.DialogResult = DialogResult.OK; buttonCancel.DialogResult = DialogResult.Cancel; label.SetBounds(9, 20, 372, 13); textBox.SetBounds(12, 36, 372, 20); buttonOk.SetBounds(228, 72, 75, 23); buttonCancel.SetBounds(309, 72, 75, 23); label.AutoSize = true; textBox.Anchor = textBox.Anchor | AnchorStyles.Right; buttonOk.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; form.ClientSize = new Size(396, 107); form.Controls.AddRange(new Control[] { label, textBox, buttonOk, buttonCancel }); form.ClientSize = new Size(Math.Max(300, label.Right + 10), form.ClientSize.Height); form.FormBorderStyle = FormBorderStyle.FixedDialog; form.StartPosition = FormStartPosition.CenterScreen; form.MinimizeBox = false; form.MaximizeBox = false; form.AcceptButton = buttonOk; form.CancelButton = buttonCancel; var dialogResult = form.ShowDialog(); value = textBox.Text; return dialogResult; } kullanım: var cevap = string.Empty; DialogResult input = InputBox("Soru", "adınız nedir?", ref cevap); if (input == DialogResult.OK & cevap != "") { MessageBox.Show("OK'a basıldı\n\nGirilen metin: " + cevap); } else { MessageBox.Show("CANCEL'a basıldı"); } Quote Link to comment Share on other sites More sharing options...
mertugruul Posted June 6, 2015 Author Share Posted June 6, 2015 Teşekkür ederim. Buna benzer bir koda rastlamıştım yabancı sitenin birisinde bilerek projeye eklemedim daha anlaşılırı lazımdı. Anlamadıktan sonra koysam bi yararı olmaz bana çok uzun. Verdiğim linkte InputBoxResult kullanılmış. Biz buna nasıl erişebiliriz bir bilginiz varmı? Tekrar teşekkür ederim. Quote Link to comment Share on other sites More sharing options...
KintaRo Posted June 6, 2015 Share Posted June 6, 2015 sanırım senin dediğin şu: http://www.reflectionit.nl/blog/2003/c-inputbox ayrıca kod uzun değil, bunu method ol bir class'ın içinde tutabilirsin, ben sık kullandığım methodları bir cs dosyasında tutuyorum, lazım olanı çağırıyorum. Quote Link to comment Share on other sites More sharing options...
Editor pairs Posted June 6, 2015 Editor Share Posted June 6, 2015 Kısaca bu şekildede halledebilirsiniz. string a = Microsoft.VisualBasic.Interaction.InputBox("mesaj", "başlık"); if (a.Length > 0) { MessageBox.Show("Evet"); } else { MessageBox.Show("Hayır"); } Quote Link to comment Share on other sites More sharing options...
mertugruul Posted June 7, 2015 Author Share Posted June 7, 2015 (edited) Tamam'a veya İptal'e basılmanın Lenght özelliğinin 0'dan büyük olması ile ne alakası var? Örneğin bir kullanıcı adı giriyorum InputBox'a daha sonra iptal'e basıyorum. Mantıksız değilmidir? Anlamadım hala. Edited June 7, 2015 by mertugruul Quote Link to comment Share on other sites More sharing options...
Editor pairs Posted June 7, 2015 Editor Share Posted June 7, 2015 Tamam'a veya İptal'e basılmanın Lenght özelliğinin 0'dan büyük olması ile ne alakası var? Örneğin bir kullanıcı adı giriyorum InputBox'a daha sonra iptal'e basıyorum. Mantıksız değilmidir? Anlamadım hala. Tamam a basarsan grilen değeri döndürür. İptale basarsan değeri sıfırlayıp döndürür. Doğal olarak gelen değer eğer 0 dan büyükse tamam a basılmıştır değilsede iptale basılmıştır. Quote Link to comment Share on other sites More sharing options...
mertugruul Posted June 7, 2015 Author Share Posted June 7, 2015 Tamam a basarsan grilen değeri döndürür. İptale basarsan değeri sıfırlayıp döndürür. Doğal olarak gelen değer eğer 0 dan büyükse tamam a basılmıştır değilsede iptale basılmıştır. Eyvallah anladım şimdi. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.