Menu
Ok, this is bugging me, and I just can't figure out what is wrong..
I have made two forms. First form just has a simple button on it, which opens the other as a dialog like so:
The second, which is that
Form2 , has two buttons on it. All I have done is to set the forms AcceptButton to one, and CancelButton to the other. In my head this is all that should be needed to make this work. But when I run it, I click on the button which opens up Form2. I can now click on the one set as CancelButton, and I get the 'Not OK' message box. But when I click on the one set as AcceptButton, nothing happens?The InitializeComponent code of Form2 looks like this:
I have done nothing else than add those two buttons, and set the AcceptButton and CancelButton. Why doesn't it work?
John Saunders
149k2222 gold badges207207 silver badges369369 bronze badges
SvishSvish
66.4k144144 gold badges393393 silver badges548548 bronze badges
5 Answers
Just setting the AcceptButton/CancelButton is not enough. This just tells which button should be invoked on Enter/Esc. You have to set the DialogResult in the Button handler.
Peter Mortensen
14.2k1919 gold badges8888 silver badges115115 bronze badges
Martin MoserMartin Moser
5,28111 gold badge2121 silver badges3737 bronze badges
Daniel A.A. Pelsmaeker
30.1k1414 gold badges8686 silver badges139139 bronze badges
SamuelSamuel
33.2k88 gold badges7777 silver badges8383 bronze badges
Definitely try the tutorial How to easily apply AcceptButton and CancelButton for custom dialog box in Winform.
Peter Mortensen
14.2k1919 gold badges8888 silver badges115115 bronze badges
user344760user344760
I had an issue with the AcceptButton not working and while the DialogResult suggestion was part of the fix, I had 2 other things that needed to change:
I hope this helps someone.
AdsAds
You need to set the KeyPreview property of the form to True, the default value is False. Remember that if focus is set to any other button rather than the AcceptButton the Enter key will execute this button
Where are all birds going? An attempt to bind flawed Morrowind AI to bring life to most beautiful birds. This plugin adds to Morrowind peaceful flying animals based on the wonderful models & textures by Lady Eternity & Proudfoot, Cait Sith, Thaedyn Vyr & Kacper/Kagz, Daduke. The scripting method used can dynamically add. Where are all birds going? An attempt to bind flawed Morrowind AI to bring life to most beautiful birds. This plugin adds to Morrowind peaceful flying animals based on the wonderful models & textures by Lady Eternity & Proudfoot, Cait Sith, Thaedyn Vyr & Kacper/Kagz, Daduke. Morrowind where are all the birds going to die.
Khaled EleftawiKhaled Eleftawi
Not the answer you're looking for? Browse other questions tagged c#winformsmodal-dialog or ask your own question.Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.
Sign up
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking âSign up for GitHubâ, you agree to our terms of service and privacy statement. Weâll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Commentscommented Jul 24, 2015
commented Jun 25, 2016
commented Jun 22, 2017
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment
HOW TOHowTo HomeMenusIcon BarMenu IconAccordionTabsVertical TabsTab HeadersFull Page TabsHover TabsTop NavigationResponsive TopnavNavbar with IconsSearch MenuSearch BarFixed SidebarSide NavigationResponsive SidebarFullscreen NavigationOff-Canvas MenuHover Sidenav ButtonsSidebar with IconsHorizontal Scroll MenuVertical MenuBottom NavigationResponsive Bottom NavBottom Border Nav LinksRight Aligned Menu LinksCentered Menu LinkEqual Width Menu LinksFixed MenuSlide Down Bar on ScrollHide Navbar on ScrollShrink Navbar on ScrollSticky NavbarNavbar on ImageHover DropdownsClick DropdownsDropdown in TopnavDropdown in SidenavResp Navbar DropdownSubnavigation MenuDropupMega MenuMobile MenuCurtain MenuCollapsed SidebarCollapsed SidepanelPaginationBreadcrumbsButton GroupVertical Button GroupSticky Social BarPill NavigationResponsive HeaderImagesSlideshowSlideshow GalleryModal ImagesLightboxResponsive Image GridImage GridTab GalleryImage Overlay FadeImage Overlay SlideImage Overlay ZoomImage Overlay TitleImage Overlay IconImage EffectsBlack and White ImageImage TextImage Text BlocksTransparent Image TextFull Page ImageForm on ImageHero ImageBlur Background ImageChange Bg on ScrollSide-by-Side ImagesRounded ImagesAvatar ImagesResponsive ImagesCenter ImagesThumbnailsMeet the TeamSticky ImageFlip an ImageShake an ImagePortfolio GalleryPortfolio with FilteringImage ZoomImage Magnifier GlassImage Comparison SliderCsgo No Accept Button MoneyButtonsAlert ButtonsOutline ButtonsSplit ButtonsAnimated ButtonsFading ButtonsButton on ImageSocial Media ButtonsRead More Read LessLoading ButtonsDownload ButtonsPill ButtonsNotification ButtonIcon ButtonsNext/prev ButtonsMore Button in NavBlock ButtonsText ButtonsRound ButtonsScroll To Top ButtonCs Go No Accept Button 2017FormsLogin FormSignup FormCheckout FormContact FormSocial Login FormRegister FormForm with IconsNewsletterStacked FormResponsive FormPopup FormInline FormClear Input FieldCopy Text to ClipboardAnimated SearchSearch ButtonFullscreen SearchInput Field in NavbarLogin Form in NavbarCustom Checkbox/RadioCustom SelectToggle SwitchCheck CheckboxDetect Caps LockTrigger Button on EnterPassword ValidationToggle Password VisibilityMultiple Step FormAutocompleteFiltersFilter ListFilter TableFilter ElementsFilter DropdownSort ListSort TableTablesZebra Striped TableResponsive TablesComparison TableMoreFullscreen VideoModal BoxesTimelineScroll IndicatorProgress BarsSkill BarRange SlidersTooltipsPopupsCollapsibleCalendarHTML IncludesTo Do ListLoadersStar RatingUser RatingOverlay EffectContact ChipsCardsFlip CardProfile CardProduct CardAlertsCalloutNotesLabelsCirclesStyle HRCouponList GroupResponsive TextCutout TextGlowing TextFixed FooterSticky ElementEqual HeightClearfixResponsive FloatsSnackbarFullscreen WindowScroll DrawingSmooth ScrollGradient Bg ScrollSticky HeaderShrink Header on ScrollPricing TableParallaxAspect RatioToggle Like/DislikeToggle Hide/ShowToggle TextToggle ClassAdd ClassRemove ClassActive ClassTree ViewRemove PropertyOffline DetectionFind Hidden ElementRedirect WebpageZoom HoverFlip BoxCenter VerticallyTransition on HoverArrowsShapesDownload LinkFull Height ElementBrowser WindowCustom ScrollbarDevice LookPlaceholder ColorText Selection ColorBullet ColorVertical LineAnimate IconsCountdown TimerTypewriterComing Soon PageChat MessagesPopup Chat WindowSplit ScreenTestimonialsSection CounterQuotes SlideshowClosable List ItemsTypical Device BreakpointsDraggable HTML ElementJS Media QueriesSyntax HighlighterJS AnimationsGet Iframe ElementsWebsiteMake a WebsiteMake a Website (W3.CSS)Make a Website (BS3)Make a Website (BS4)Center WebsiteContact SectionBig HeaderExample WebsiteGrid2 Column Layout3 Column Layout4 Column LayoutExpanding GridList Grid ViewMixed Column LayoutColumn CardsZig Zag LayoutBlog LayoutConvertersConvert WeightConvert TemperatureConvert LengthConvert SpeedPythonRemove List DuplicatesReverse a StringComments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |